blob: 43e70ff1e5789aca34086c7df856707fd580982c [file] [log] [blame]
William A. Kennington III48c42752018-07-17 14:40:14 -07001#include <cerrno>
William A. Kennington III5320b1f2019-03-29 20:00:37 -07002#include <functional>
William A. Kennington III0a816c52018-07-17 14:40:14 -07003#include <gmock/gmock.h>
4#include <gtest/gtest.h>
William A. Kennington III715c72f2018-07-17 14:40:14 -07005#include <memory>
William A. Kennington IIIe04cb032018-11-13 14:28:36 -08006#include <optional>
William A. Kennington III715c72f2018-07-17 14:40:14 -07007#include <sdeventplus/event.hpp>
William A. Kennington III65db8632018-07-17 14:40:14 -07008#include <sdeventplus/exception.hpp>
William A. Kennington III0a816c52018-07-17 14:40:14 -07009#include <sdeventplus/internal/sdevent.hpp>
10#include <sdeventplus/source/base.hpp>
11#include <sdeventplus/test/sdevent.hpp>
William A. Kennington III5320b1f2019-03-29 20:00:37 -070012#include <sdeventplus/types.hpp>
William A. Kennington III65db8632018-07-17 14:40:14 -070013#include <string>
William A. Kennington III715c72f2018-07-17 14:40:14 -070014#include <systemd/sd-event.h>
William A. Kennington III5320b1f2019-03-29 20:00:37 -070015#include <tuple>
William A. Kennington III0a816c52018-07-17 14:40:14 -070016#include <type_traits>
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -070017#include <utility>
William A. Kennington III0a816c52018-07-17 14:40:14 -070018
19namespace sdeventplus
20{
21namespace source
22{
23namespace
24{
25
William A. Kennington III65db8632018-07-17 14:40:14 -070026using testing::DoAll;
William A. Kennington III0a816c52018-07-17 14:40:14 -070027using testing::Return;
William A. Kennington III48c42752018-07-17 14:40:14 -070028using testing::SaveArg;
William A. Kennington III65db8632018-07-17 14:40:14 -070029using testing::SetArgPointee;
William A. Kennington III0a816c52018-07-17 14:40:14 -070030
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070031using UniqueEvent = std::unique_ptr<Event, std::function<void(Event*)>>;
32
William A. Kennington III5320b1f2019-03-29 20:00:37 -070033class BaseImplData;
34
William A. Kennington III0a816c52018-07-17 14:40:14 -070035class BaseImpl : public Base
36{
37 public:
William A. Kennington III5320b1f2019-03-29 20:00:37 -070038 BaseImpl(const Event& event, sd_event_source* source, std::false_type);
39
40 BaseImpl(const BaseImpl& other, sdeventplus::internal::NoOwn) :
41 Base(other, sdeventplus::internal::NoOwn())
William A. Kennington III0a816c52018-07-17 14:40:14 -070042 {
43 }
William A. Kennington IIIe0f1d192018-07-17 17:00:56 -070044
45 using Base::get_prepare;
William A. Kennington III0a816c52018-07-17 14:40:14 -070046};
47
William A. Kennington III5320b1f2019-03-29 20:00:37 -070048class BaseImplData : public BaseImpl, public detail::BaseData
49{
50 public:
51 BaseImplData(const BaseImpl& base) :
52 BaseImpl(base, sdeventplus::internal::NoOwn()), BaseData(base)
53 {
54 }
55};
56
57BaseImpl::BaseImpl(const Event& event, sd_event_source* source,
58 std::false_type) :
59 Base(event, source, std::false_type())
60{
61 set_userdata(std::make_unique<BaseImplData>(*this));
62}
63
William A. Kennington III0a816c52018-07-17 14:40:14 -070064class BaseTest : public testing::Test
65{
66 protected:
67 testing::StrictMock<test::SdEventMock> mock;
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070068 sd_event_source* const expected_source =
69 reinterpret_cast<sd_event_source*>(1234);
William A. Kennington III5320b1f2019-03-29 20:00:37 -070070 sd_event_source* const expected_source2 =
71 reinterpret_cast<sd_event_source*>(3456);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070072 sd_event* const expected_event = reinterpret_cast<sd_event*>(2345);
William A. Kennington III5320b1f2019-03-29 20:00:37 -070073 sd_event* const expected_event2 = reinterpret_cast<sd_event*>(4567);
74
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070075 UniqueEvent event = make_event(expected_event);
William A. Kennington III715c72f2018-07-17 14:40:14 -070076
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070077 UniqueEvent make_event(sd_event* event)
William A. Kennington III715c72f2018-07-17 14:40:14 -070078 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070079 auto deleter = [this, event](Event* e) {
80 EXPECT_CALL(this->mock, sd_event_unref(event))
81 .WillOnce(Return(nullptr));
82 delete e;
83 };
84 return UniqueEvent(new Event(event, std::false_type(), &mock), deleter);
William A. Kennington III715c72f2018-07-17 14:40:14 -070085 }
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070086
87 // Using a unique_ptr to make sure we don't get any superfluous moves or
88 // copies.
William A. Kennington III5320b1f2019-03-29 20:00:37 -070089 std::tuple<std::unique_ptr<BaseImpl>, std::function<void()>>
90 make_base(const Event& event, sd_event_source* source)
William A. Kennington III715c72f2018-07-17 14:40:14 -070091 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070092 EXPECT_CALL(mock, sd_event_ref(event.get()))
93 .WillOnce(Return(event.get()));
William A. Kennington III5320b1f2019-03-29 20:00:37 -070094 sd_event_destroy_t destroy;
William A. Kennington III2d943ea2018-07-17 14:40:14 -070095 void* userdata;
William A. Kennington III5320b1f2019-03-29 20:00:37 -070096 {
97 testing::InSequence seq;
98 EXPECT_CALL(
99 mock, sd_event_source_set_destroy_callback(source, testing::_))
100 .WillOnce(DoAll(SaveArg<1>(&destroy), Return(0)));
101 EXPECT_CALL(mock, sd_event_source_set_userdata(source, testing::_))
102 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
103 }
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700104 auto ret = std::make_unique<BaseImpl>(event, source, std::false_type());
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700105 EXPECT_CALL(mock, sd_event_source_get_userdata(source))
106 .WillRepeatedly(Return(userdata));
107 EXPECT_NE(ret.get(), userdata);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700108 EXPECT_EQ(source, ret->get());
109 EXPECT_NE(&event, &ret->get_event());
110 EXPECT_EQ(event.get(), ret->get_event().get());
111 EXPECT_FALSE(ret->get_prepare());
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700112 return {std::move(ret), std::bind(destroy, userdata)};
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700113 }
114
William A. Kennington IIIe0f1d192018-07-17 17:00:56 -0700115 void set_prepare_placeholder(BaseImpl& base)
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700116 {
117 EXPECT_CALL(mock, sd_event_source_set_prepare(base.get(), testing::_))
118 .WillOnce(Return(0));
119 base.set_prepare([](Base&) {});
120 EXPECT_TRUE(base.get_prepare());
121 }
122
123 void empty_base(BaseImpl&& other)
124 {
125 BaseImpl mover(std::move(other));
William A. Kennington IIIe04cb032018-11-13 14:28:36 -0800126 EXPECT_THROW(other.get(), std::bad_optional_access);
127 EXPECT_THROW(other.get_event().get(), std::bad_optional_access);
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700128 EXPECT_THROW(other.get_prepare(), std::bad_optional_access);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700129
130 expect_base_destruct(mover.get_event(), mover.get());
131 }
132
133 void expect_base_destruct(const Event& event, sd_event_source* source)
134 {
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700135 EXPECT_CALL(mock, sd_event_source_unref(source))
136 .WillOnce(Return(nullptr));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700137 EXPECT_CALL(mock, sd_event_unref(event.get()))
William A. Kennington III715c72f2018-07-17 14:40:14 -0700138 .WillOnce(Return(nullptr));
William A. Kennington III715c72f2018-07-17 14:40:14 -0700139 }
William A. Kennington III0a816c52018-07-17 14:40:14 -0700140};
141
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700142TEST_F(BaseTest, NewBaseFail)
143{
144 EXPECT_CALL(mock, sd_event_ref(expected_event))
145 .WillOnce(Return(expected_event));
146 EXPECT_CALL(
147 mock, sd_event_source_set_destroy_callback(expected_source, testing::_))
148 .WillOnce(Return(-EINVAL));
149 expect_base_destruct(*event, expected_source);
150 EXPECT_THROW(BaseImpl(*event, expected_source, std::false_type()),
151 SdEventError);
152}
153
William A. Kennington III0a816c52018-07-17 14:40:14 -0700154TEST_F(BaseTest, NewBaseNoRef)
155{
William A. Kennington III715c72f2018-07-17 14:40:14 -0700156 EXPECT_CALL(mock, sd_event_ref(expected_event))
157 .WillOnce(Return(expected_event));
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700158 sd_event_destroy_t destroy;
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700159 void* userdata;
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700160 {
161 testing::InSequence seq;
162 EXPECT_CALL(mock, sd_event_source_set_destroy_callback(expected_source,
163 testing::_))
164 .WillOnce(DoAll(SaveArg<1>(&destroy), Return(0)));
165 EXPECT_CALL(mock,
166 sd_event_source_set_userdata(expected_source, testing::_))
167 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
168 }
William A. Kennington III715c72f2018-07-17 14:40:14 -0700169 BaseImpl source(*event, expected_source, std::false_type());
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700170 EXPECT_NE(&source, userdata);
William A. Kennington III4863b962018-07-17 14:40:14 -0700171 EXPECT_EQ(expected_source, source.get());
172 EXPECT_NE(event.get(), &source.get_event());
173 EXPECT_EQ(expected_event, source.get_event().get());
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700174
175 EXPECT_CALL(mock, sd_event_source_get_userdata(expected_source))
176 .WillOnce(Return(userdata));
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700177 EXPECT_FALSE(source.get_prepare());
William A. Kennington III0a816c52018-07-17 14:40:14 -0700178
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700179 expect_base_destruct(*event, expected_source);
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700180 destroy(userdata);
William A. Kennington III7c24e052018-07-17 14:40:14 -0700181}
182
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700183TEST_F(BaseTest, UserdataOutlives)
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700184{
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700185 EXPECT_CALL(mock, sd_event_ref(expected_event))
186 .WillOnce(Return(expected_event));
187 sd_event_destroy_t destroy;
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700188 void* userdata;
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700189 {
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700190 testing::InSequence seq;
191 EXPECT_CALL(mock, sd_event_source_set_destroy_callback(expected_source,
192 testing::_))
193 .WillOnce(DoAll(SaveArg<1>(&destroy), Return(0)));
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700194 EXPECT_CALL(mock,
195 sd_event_source_set_userdata(expected_source, testing::_))
196 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700197 }
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700198 auto source =
199 std::make_unique<BaseImpl>(*event, expected_source, std::false_type());
200 EXPECT_CALL(mock, sd_event_source_get_userdata(expected_source))
201 .WillRepeatedly(Return(userdata));
202 EXPECT_FALSE(source->get_prepare());
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700203
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700204 expect_base_destruct(*event, expected_source);
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700205 source.reset();
206 EXPECT_FALSE(reinterpret_cast<BaseImpl*>(userdata)->get_prepare());
207 destroy(userdata);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700208}
209
William A. Kennington III56dc78b2019-03-29 21:09:13 -0700210TEST_F(BaseTest, CopyCorrectness)
211{
212 std::unique_ptr<BaseImpl> base1, base2;
213 std::function<void()> destroy;
214 std::tie(base1, destroy) = make_base(*event, expected_source);
215 set_prepare_placeholder(*base1);
216 EXPECT_TRUE(base1->get_prepare());
217
218 EXPECT_CALL(mock, sd_event_ref(expected_event))
219 .WillOnce(Return(expected_event));
220 EXPECT_CALL(mock, sd_event_source_ref(expected_source))
221 .WillOnce(Return(expected_source));
222 base2 = std::make_unique<BaseImpl>(*base1);
223 EXPECT_EQ(&base1->get_prepare(), &base2->get_prepare());
224
225 empty_base(std::move(*base1));
226 EXPECT_THROW(base1->get_prepare(), std::bad_optional_access);
227 EXPECT_CALL(mock, sd_event_ref(expected_event))
228 .WillOnce(Return(expected_event));
229 EXPECT_CALL(mock, sd_event_source_ref(expected_source))
230 .WillOnce(Return(expected_source));
231 *base1 = *base2;
232 EXPECT_EQ(&base1->get_prepare(), &base2->get_prepare());
233
234 expect_base_destruct(*event, expected_source);
235 base2.reset();
236 expect_base_destruct(*event, expected_source);
237 base1.reset();
238 destroy();
239}
240
William A. Kennington III65db8632018-07-17 14:40:14 -0700241class BaseMethodTest : public BaseTest
242{
243 protected:
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700244 std::unique_ptr<BaseImpl> base;
245 std::function<void()> destroy;
246
247 void SetUp()
248 {
249 std::tie(base, destroy) = make_base(*event, expected_source);
250 }
William A. Kennington III65db8632018-07-17 14:40:14 -0700251
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700252 void TearDown()
William A. Kennington III65db8632018-07-17 14:40:14 -0700253 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700254 expect_base_destruct(base->get_event(), base->get());
William A. Kennington III715c72f2018-07-17 14:40:14 -0700255 base.reset();
William A. Kennington III5320b1f2019-03-29 20:00:37 -0700256 destroy();
William A. Kennington III65db8632018-07-17 14:40:14 -0700257 }
258};
259
260TEST_F(BaseMethodTest, GetDescriptionSuccess)
261{
262 const char* expected = "test_desc";
263 EXPECT_CALL(mock,
264 sd_event_source_get_description(expected_source, testing::_))
265 .WillOnce(DoAll(SetArgPointee<1>(expected), Return(0)));
266 // Intentionally comparing pointers to make sure no copying is happening
267 EXPECT_EQ(expected, base->get_description());
268}
269
270TEST_F(BaseMethodTest, GetDescriptionError)
271{
272 EXPECT_CALL(mock,
273 sd_event_source_get_description(expected_source, testing::_))
274 .WillOnce(Return(-EINVAL));
275 EXPECT_THROW(base->get_description(), SdEventError);
276}
277
278TEST_F(BaseMethodTest, SetDescriptionSuccess)
279{
280 const char* expected = "test desc";
281 // Intentionally comparing pointers to make sure no copying is happening
282 EXPECT_CALL(mock,
283 sd_event_source_set_description(expected_source, expected))
284 .WillOnce(Return(0));
285 base->set_description(expected);
286}
287
288TEST_F(BaseMethodTest, SetDescriptionError)
289{
290 const char* expected = "test desc";
291 // Intentionally comparing pointers to make sure no copying is happening
292 EXPECT_CALL(mock,
293 sd_event_source_set_description(expected_source, expected))
294 .WillOnce(Return(-EINVAL));
295 EXPECT_THROW(base->set_description(expected), SdEventError);
296}
297
William A. Kennington III48c42752018-07-17 14:40:14 -0700298TEST_F(BaseMethodTest, SetPrepareCallback)
299{
300 bool completed = false;
301 Base::Callback callback = [&completed](Base&) { completed = true; };
302 sd_event_handler_t event_handler;
303 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
304 .WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
305 base->set_prepare(std::move(callback));
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700306 EXPECT_TRUE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700307 EXPECT_FALSE(callback);
308 EXPECT_FALSE(completed);
309
310 EXPECT_EQ(0, event_handler(nullptr, base.get()));
311 EXPECT_TRUE(completed);
312}
313
314TEST_F(BaseMethodTest, SetPrepareCallbackNoUserdata)
315{
316 Base::Callback callback = [](Base&) {};
317 sd_event_handler_t event_handler;
318 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
319 .WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
320 base->set_prepare(std::move(callback));
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700321 EXPECT_TRUE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700322 EXPECT_FALSE(callback);
323
324 EXPECT_EQ(-EINVAL, event_handler(nullptr, nullptr));
325}
326
William A. Kennington III48c42752018-07-17 14:40:14 -0700327TEST_F(BaseMethodTest, SetPrepareError)
328{
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700329 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
330 .WillOnce(Return(0));
William A. Kennington III651e87a2018-12-11 16:45:37 -0800331 base->set_prepare([](Base&) {});
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700332 EXPECT_TRUE(base->get_prepare());
333
William A. Kennington III48c42752018-07-17 14:40:14 -0700334 Base::Callback callback = [](Base&) {};
335 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
336 .WillOnce(Return(-EINVAL));
337 EXPECT_THROW(base->set_prepare(std::move(callback)), SdEventError);
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700338 EXPECT_FALSE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700339 EXPECT_TRUE(callback);
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700340}
341
342TEST_F(BaseMethodTest, SetPrepareNull)
343{
344 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
345 .WillOnce(Return(0));
William A. Kennington III651e87a2018-12-11 16:45:37 -0800346 base->set_prepare([](Base&) {});
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700347 EXPECT_TRUE(base->get_prepare());
348
349 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, nullptr))
350 .WillOnce(Return(0));
351 base->set_prepare(nullptr);
352 EXPECT_FALSE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700353}
354
William A. Kennington III65db8632018-07-17 14:40:14 -0700355TEST_F(BaseMethodTest, GetPendingSuccess)
356{
357 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
358 .WillOnce(Return(0));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700359 EXPECT_FALSE(base->get_pending());
William A. Kennington III65db8632018-07-17 14:40:14 -0700360 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
361 .WillOnce(Return(4));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700362 EXPECT_TRUE(base->get_pending());
William A. Kennington III65db8632018-07-17 14:40:14 -0700363}
364
365TEST_F(BaseMethodTest, GetPendingError)
366{
367 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
368 .WillOnce(Return(-EINVAL));
369 EXPECT_THROW(base->get_pending(), SdEventError);
370}
371
372TEST_F(BaseMethodTest, GetPrioritySuccess)
373{
374 EXPECT_CALL(mock, sd_event_source_get_priority(expected_source, testing::_))
375 .WillOnce(DoAll(SetArgPointee<1>(1024), Return(0)));
376 EXPECT_EQ(1024, base->get_priority());
377}
378
379TEST_F(BaseMethodTest, GetPriorityError)
380{
381 EXPECT_CALL(mock, sd_event_source_get_priority(expected_source, testing::_))
382 .WillOnce(Return(-EINVAL));
383 EXPECT_THROW(base->get_priority(), SdEventError);
384}
385
386TEST_F(BaseMethodTest, SetPrioritySuccess)
387{
388 EXPECT_CALL(mock, sd_event_source_set_priority(expected_source, 1024))
389 .WillOnce(Return(0));
390 base->set_priority(1024);
391}
392
393TEST_F(BaseMethodTest, SetPriorityError)
394{
395 EXPECT_CALL(mock, sd_event_source_set_priority(expected_source, 1024))
396 .WillOnce(Return(-EINVAL));
397 EXPECT_THROW(base->set_priority(1024), SdEventError);
398}
399
400TEST_F(BaseMethodTest, GetEnabledSuccess)
401{
402 EXPECT_CALL(mock, sd_event_source_get_enabled(expected_source, testing::_))
403 .WillOnce(DoAll(SetArgPointee<1>(SD_EVENT_ON), Return(0)));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700404 EXPECT_EQ(Enabled::On, base->get_enabled());
William A. Kennington III65db8632018-07-17 14:40:14 -0700405}
406
407TEST_F(BaseMethodTest, GetEnabledError)
408{
409 EXPECT_CALL(mock, sd_event_source_get_enabled(expected_source, testing::_))
410 .WillOnce(Return(-EINVAL));
411 EXPECT_THROW(base->get_enabled(), SdEventError);
412}
413
414TEST_F(BaseMethodTest, SetEnabledSuccess)
415{
416 EXPECT_CALL(mock, sd_event_source_set_enabled(expected_source, SD_EVENT_ON))
417 .WillOnce(Return(0));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700418 base->set_enabled(Enabled::On);
William A. Kennington III65db8632018-07-17 14:40:14 -0700419}
420
421TEST_F(BaseMethodTest, SetEnabledError)
422{
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700423 EXPECT_CALL(mock,
424 sd_event_source_set_enabled(expected_source, SD_EVENT_ONESHOT))
William A. Kennington III65db8632018-07-17 14:40:14 -0700425 .WillOnce(Return(-EINVAL));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700426 EXPECT_THROW(base->set_enabled(Enabled::OneShot), SdEventError);
William A. Kennington III0a816c52018-07-17 14:40:14 -0700427}
428
429} // namespace
430} // namespace source
431} // namespace sdeventplus