blob: 27e5bc3e8c5a6a6b1721ccc8fe95faae495a33c3 [file] [log] [blame]
William A. Kennington III48c42752018-07-17 14:40:14 -07001#include <cerrno>
William A. Kennington III0a816c52018-07-17 14:40:14 -07002#include <gmock/gmock.h>
3#include <gtest/gtest.h>
William A. Kennington III715c72f2018-07-17 14:40:14 -07004#include <memory>
William A. Kennington IIIe04cb032018-11-13 14:28:36 -08005#include <optional>
William A. Kennington III715c72f2018-07-17 14:40:14 -07006#include <sdeventplus/event.hpp>
William A. Kennington III65db8632018-07-17 14:40:14 -07007#include <sdeventplus/exception.hpp>
William A. Kennington III0a816c52018-07-17 14:40:14 -07008#include <sdeventplus/internal/sdevent.hpp>
9#include <sdeventplus/source/base.hpp>
10#include <sdeventplus/test/sdevent.hpp>
William A. Kennington III65db8632018-07-17 14:40:14 -070011#include <string>
William A. Kennington III715c72f2018-07-17 14:40:14 -070012#include <systemd/sd-event.h>
William A. Kennington III0a816c52018-07-17 14:40:14 -070013#include <type_traits>
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -070014#include <utility>
William A. Kennington III0a816c52018-07-17 14:40:14 -070015
16namespace sdeventplus
17{
18namespace source
19{
20namespace
21{
22
William A. Kennington III65db8632018-07-17 14:40:14 -070023using testing::DoAll;
William A. Kennington III0a816c52018-07-17 14:40:14 -070024using testing::Return;
William A. Kennington III48c42752018-07-17 14:40:14 -070025using testing::SaveArg;
William A. Kennington III65db8632018-07-17 14:40:14 -070026using testing::SetArgPointee;
William A. Kennington III0a816c52018-07-17 14:40:14 -070027
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070028using UniqueEvent = std::unique_ptr<Event, std::function<void(Event*)>>;
29
William A. Kennington III0a816c52018-07-17 14:40:14 -070030class BaseImpl : public Base
31{
32 public:
William A. Kennington III715c72f2018-07-17 14:40:14 -070033 BaseImpl(const Event& event, sd_event_source* source, std::false_type) :
34 Base(event, source, std::false_type())
William A. Kennington III0a816c52018-07-17 14:40:14 -070035 {
36 }
William A. Kennington IIIe0f1d192018-07-17 17:00:56 -070037
38 using Base::get_prepare;
William A. Kennington III0a816c52018-07-17 14:40:14 -070039};
40
41class BaseTest : public testing::Test
42{
43 protected:
44 testing::StrictMock<test::SdEventMock> mock;
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070045 sd_event_source* const expected_source =
46 reinterpret_cast<sd_event_source*>(1234);
47 sd_event* const expected_event = reinterpret_cast<sd_event*>(2345);
48 UniqueEvent event = make_event(expected_event);
William A. Kennington III715c72f2018-07-17 14:40:14 -070049
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070050 UniqueEvent make_event(sd_event* event)
William A. Kennington III715c72f2018-07-17 14:40:14 -070051 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070052 auto deleter = [this, event](Event* e) {
53 EXPECT_CALL(this->mock, sd_event_unref(event))
54 .WillOnce(Return(nullptr));
55 delete e;
56 };
57 return UniqueEvent(new Event(event, std::false_type(), &mock), deleter);
William A. Kennington III715c72f2018-07-17 14:40:14 -070058 }
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070059
60 // Using a unique_ptr to make sure we don't get any superfluous moves or
61 // copies.
62 std::unique_ptr<BaseImpl> make_base(const Event& event,
63 sd_event_source* source)
William A. Kennington III715c72f2018-07-17 14:40:14 -070064 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070065 EXPECT_CALL(mock, sd_event_ref(event.get()))
66 .WillOnce(Return(event.get()));
William A. Kennington III2d943ea2018-07-17 14:40:14 -070067 void* userdata;
68 EXPECT_CALL(mock, sd_event_source_set_userdata(source, testing::_))
69 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070070 auto ret = std::make_unique<BaseImpl>(event, source, std::false_type());
William A. Kennington III2d943ea2018-07-17 14:40:14 -070071 EXPECT_EQ(ret.get(), userdata);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070072 EXPECT_EQ(source, ret->get());
73 EXPECT_NE(&event, &ret->get_event());
74 EXPECT_EQ(event.get(), ret->get_event().get());
75 EXPECT_FALSE(ret->get_prepare());
76 return ret;
77 }
78
William A. Kennington IIIe0f1d192018-07-17 17:00:56 -070079 void set_prepare_placeholder(BaseImpl& base)
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070080 {
81 EXPECT_CALL(mock, sd_event_source_set_prepare(base.get(), testing::_))
82 .WillOnce(Return(0));
83 base.set_prepare([](Base&) {});
84 EXPECT_TRUE(base.get_prepare());
85 }
86
87 void empty_base(BaseImpl&& other)
88 {
William A. Kennington III2d943ea2018-07-17 14:40:14 -070089 void* userdata;
90 EXPECT_CALL(mock, sd_event_source_set_userdata(other.get(), testing::_))
91 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070092 BaseImpl mover(std::move(other));
William A. Kennington III2d943ea2018-07-17 14:40:14 -070093 EXPECT_EQ(&mover, userdata);
William A. Kennington IIIe04cb032018-11-13 14:28:36 -080094 EXPECT_THROW(other.get(), std::bad_optional_access);
95 EXPECT_THROW(other.get_event().get(), std::bad_optional_access);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -070096 EXPECT_FALSE(other.get_prepare());
97
98 expect_base_destruct(mover.get_event(), mover.get());
99 }
100
101 void expect_base_destruct(const Event& event, sd_event_source* source)
102 {
103 {
104 testing::InSequence seq;
105 EXPECT_CALL(mock, sd_event_source_set_enabled(source, SD_EVENT_OFF))
106 .WillOnce(Return(0));
107 EXPECT_CALL(mock, sd_event_source_unref(source))
108 .WillOnce(Return(nullptr));
109 }
110 EXPECT_CALL(mock, sd_event_unref(event.get()))
William A. Kennington III715c72f2018-07-17 14:40:14 -0700111 .WillOnce(Return(nullptr));
William A. Kennington III715c72f2018-07-17 14:40:14 -0700112 }
William A. Kennington III0a816c52018-07-17 14:40:14 -0700113};
114
William A. Kennington III0a816c52018-07-17 14:40:14 -0700115TEST_F(BaseTest, NewBaseNoRef)
116{
William A. Kennington III715c72f2018-07-17 14:40:14 -0700117 EXPECT_CALL(mock, sd_event_ref(expected_event))
118 .WillOnce(Return(expected_event));
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700119 void* userdata;
120 EXPECT_CALL(mock, sd_event_source_set_userdata(expected_source, testing::_))
121 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington III715c72f2018-07-17 14:40:14 -0700122 BaseImpl source(*event, expected_source, std::false_type());
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700123 EXPECT_EQ(&source, userdata);
William A. Kennington III4863b962018-07-17 14:40:14 -0700124 EXPECT_EQ(expected_source, source.get());
125 EXPECT_NE(event.get(), &source.get_event());
126 EXPECT_EQ(expected_event, source.get_event().get());
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700127 EXPECT_FALSE(source.get_prepare());
William A. Kennington III0a816c52018-07-17 14:40:14 -0700128
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700129 expect_base_destruct(*event, expected_source);
William A. Kennington III7c24e052018-07-17 14:40:14 -0700130}
131
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700132TEST_F(BaseTest, MoveConstruct)
133{
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700134 std::unique_ptr<BaseImpl> source1 = make_base(*event, expected_source);
135 set_prepare_placeholder(*source1);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700136
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700137 void* userdata;
138 EXPECT_CALL(mock, sd_event_source_set_userdata(expected_source, testing::_))
139 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700140 BaseImpl source2(std::move(*source1));
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700141 EXPECT_EQ(&source2, userdata);
William A. Kennington IIIe04cb032018-11-13 14:28:36 -0800142 EXPECT_THROW(source1->get(), std::bad_optional_access);
143 EXPECT_THROW(source1->get_event().get(), std::bad_optional_access);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700144 EXPECT_FALSE(source1->get_prepare());
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700145 EXPECT_EQ(expected_source, source2.get());
146 EXPECT_EQ(expected_event, source2.get_event().get());
147 EXPECT_TRUE(source2.get_prepare());
148
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700149 expect_base_destruct(*event, expected_source);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700150}
151
152TEST_F(BaseTest, MoveAssignSelf)
153{
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700154 std::unique_ptr<BaseImpl> source1 = make_base(*event, expected_source);
155 set_prepare_placeholder(*source1);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700156
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700157 *source1 = std::move(*source1);
158 EXPECT_EQ(expected_source, source1->get());
159 EXPECT_EQ(expected_event, source1->get_event().get());
160 EXPECT_TRUE(source1->get_prepare());
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700161
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700162 expect_base_destruct(*event, expected_source);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700163}
164
165TEST_F(BaseTest, MoveAssignEmpty)
166{
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700167 std::unique_ptr<BaseImpl> source1 = make_base(*event, expected_source);
168 set_prepare_placeholder(*source1);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700169
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700170 std::unique_ptr<BaseImpl> source2 = make_base(*event, expected_source);
171 empty_base(std::move(*source2));
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700172
173 {
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700174 void* userdata;
175 EXPECT_CALL(mock,
176 sd_event_source_set_userdata(expected_source, testing::_))
177 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700178 *source2 = std::move(*source1);
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700179 EXPECT_EQ(source2.get(), userdata);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700180 }
William A. Kennington IIIe04cb032018-11-13 14:28:36 -0800181 EXPECT_THROW(source1->get(), std::bad_optional_access);
182 EXPECT_THROW(source1->get_event().get(), std::bad_optional_access);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700183 EXPECT_FALSE(source1->get_prepare());
184 EXPECT_EQ(expected_source, source2->get());
185 EXPECT_EQ(expected_event, source2->get_event().get());
186 EXPECT_TRUE(source2->get_prepare());
187
188 // Make sure source1 is deleted to ensure it isn't holding a reference
189 source1.reset();
190 expect_base_destruct(*event, expected_source);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700191}
192
193TEST_F(BaseTest, MoveAssignExisting)
194{
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700195 sd_event_source* const expected_source2 =
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700196 reinterpret_cast<sd_event_source*>(3456);
197 sd_event* const expected_event2 = reinterpret_cast<sd_event*>(4567);
198
199 std::unique_ptr<BaseImpl> source1 = make_base(*event, expected_source);
200 set_prepare_placeholder(*source1);
201
202 UniqueEvent event2 = make_event(expected_event2);
203 std::unique_ptr<BaseImpl> source2 = make_base(*event2, expected_source2);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700204
205 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700206 expect_base_destruct(*event2, expected_source2);
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700207 void* userdata;
208 EXPECT_CALL(mock,
209 sd_event_source_set_userdata(expected_source, testing::_))
210 .WillOnce(DoAll(SaveArg<1>(&userdata), Return(nullptr)));
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700211 *source2 = std::move(*source1);
William A. Kennington III2d943ea2018-07-17 14:40:14 -0700212 EXPECT_EQ(source2.get(), userdata);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700213 }
William A. Kennington IIIe04cb032018-11-13 14:28:36 -0800214 EXPECT_THROW(source1->get(), std::bad_optional_access);
215 EXPECT_THROW(source1->get_event().get(), std::bad_optional_access);
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700216 EXPECT_FALSE(source1->get_prepare());
217 EXPECT_EQ(expected_source, source2->get());
218 EXPECT_EQ(expected_event, source2->get_event().get());
219 EXPECT_TRUE(source2->get_prepare());
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700220
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700221 // Make sure source1 is deleted to ensure it isn't holding a reference
222 source1.reset();
223 expect_base_destruct(*event, expected_source);
William A. Kennington IIIcc6b12b2018-07-17 14:40:14 -0700224}
225
William A. Kennington III65db8632018-07-17 14:40:14 -0700226class BaseMethodTest : public BaseTest
227{
228 protected:
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700229 std::unique_ptr<BaseImpl> base = make_base(*event, expected_source);
William A. Kennington III65db8632018-07-17 14:40:14 -0700230
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700231 void TearDown()
William A. Kennington III65db8632018-07-17 14:40:14 -0700232 {
William A. Kennington IIIe3e1df02018-07-17 14:40:14 -0700233 expect_base_destruct(base->get_event(), base->get());
William A. Kennington III715c72f2018-07-17 14:40:14 -0700234 base.reset();
William A. Kennington III65db8632018-07-17 14:40:14 -0700235 }
236};
237
238TEST_F(BaseMethodTest, GetDescriptionSuccess)
239{
240 const char* expected = "test_desc";
241 EXPECT_CALL(mock,
242 sd_event_source_get_description(expected_source, testing::_))
243 .WillOnce(DoAll(SetArgPointee<1>(expected), Return(0)));
244 // Intentionally comparing pointers to make sure no copying is happening
245 EXPECT_EQ(expected, base->get_description());
246}
247
248TEST_F(BaseMethodTest, GetDescriptionError)
249{
250 EXPECT_CALL(mock,
251 sd_event_source_get_description(expected_source, testing::_))
252 .WillOnce(Return(-EINVAL));
253 EXPECT_THROW(base->get_description(), SdEventError);
254}
255
256TEST_F(BaseMethodTest, SetDescriptionSuccess)
257{
258 const char* expected = "test desc";
259 // Intentionally comparing pointers to make sure no copying is happening
260 EXPECT_CALL(mock,
261 sd_event_source_set_description(expected_source, expected))
262 .WillOnce(Return(0));
263 base->set_description(expected);
264}
265
266TEST_F(BaseMethodTest, SetDescriptionError)
267{
268 const char* expected = "test desc";
269 // Intentionally comparing pointers to make sure no copying is happening
270 EXPECT_CALL(mock,
271 sd_event_source_set_description(expected_source, expected))
272 .WillOnce(Return(-EINVAL));
273 EXPECT_THROW(base->set_description(expected), SdEventError);
274}
275
William A. Kennington III48c42752018-07-17 14:40:14 -0700276TEST_F(BaseMethodTest, SetPrepareCallback)
277{
278 bool completed = false;
279 Base::Callback callback = [&completed](Base&) { completed = true; };
280 sd_event_handler_t event_handler;
281 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
282 .WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
283 base->set_prepare(std::move(callback));
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700284 EXPECT_TRUE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700285 EXPECT_FALSE(callback);
286 EXPECT_FALSE(completed);
287
288 EXPECT_EQ(0, event_handler(nullptr, base.get()));
289 EXPECT_TRUE(completed);
290}
291
292TEST_F(BaseMethodTest, SetPrepareCallbackNoUserdata)
293{
294 Base::Callback callback = [](Base&) {};
295 sd_event_handler_t event_handler;
296 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
297 .WillOnce(DoAll(SaveArg<1>(&event_handler), Return(0)));
298 base->set_prepare(std::move(callback));
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700299 EXPECT_TRUE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700300 EXPECT_FALSE(callback);
301
302 EXPECT_EQ(-EINVAL, event_handler(nullptr, nullptr));
303}
304
William A. Kennington III48c42752018-07-17 14:40:14 -0700305TEST_F(BaseMethodTest, SetPrepareError)
306{
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700307 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
308 .WillOnce(Return(0));
William A. Kennington III651e87a2018-12-11 16:45:37 -0800309 base->set_prepare([](Base&) {});
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700310 EXPECT_TRUE(base->get_prepare());
311
William A. Kennington III48c42752018-07-17 14:40:14 -0700312 Base::Callback callback = [](Base&) {};
313 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
314 .WillOnce(Return(-EINVAL));
315 EXPECT_THROW(base->set_prepare(std::move(callback)), SdEventError);
William A. Kennington IIIf5285c72018-07-17 14:40:14 -0700316 EXPECT_FALSE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700317 EXPECT_TRUE(callback);
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700318}
319
320TEST_F(BaseMethodTest, SetPrepareNull)
321{
322 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, testing::_))
323 .WillOnce(Return(0));
William A. Kennington III651e87a2018-12-11 16:45:37 -0800324 base->set_prepare([](Base&) {});
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -0700325 EXPECT_TRUE(base->get_prepare());
326
327 EXPECT_CALL(mock, sd_event_source_set_prepare(expected_source, nullptr))
328 .WillOnce(Return(0));
329 base->set_prepare(nullptr);
330 EXPECT_FALSE(base->get_prepare());
William A. Kennington III48c42752018-07-17 14:40:14 -0700331}
332
William A. Kennington III65db8632018-07-17 14:40:14 -0700333TEST_F(BaseMethodTest, GetPendingSuccess)
334{
335 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
336 .WillOnce(Return(0));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700337 EXPECT_FALSE(base->get_pending());
William A. Kennington III65db8632018-07-17 14:40:14 -0700338 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
339 .WillOnce(Return(4));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700340 EXPECT_TRUE(base->get_pending());
William A. Kennington III65db8632018-07-17 14:40:14 -0700341}
342
343TEST_F(BaseMethodTest, GetPendingError)
344{
345 EXPECT_CALL(mock, sd_event_source_get_pending(expected_source))
346 .WillOnce(Return(-EINVAL));
347 EXPECT_THROW(base->get_pending(), SdEventError);
348}
349
350TEST_F(BaseMethodTest, GetPrioritySuccess)
351{
352 EXPECT_CALL(mock, sd_event_source_get_priority(expected_source, testing::_))
353 .WillOnce(DoAll(SetArgPointee<1>(1024), Return(0)));
354 EXPECT_EQ(1024, base->get_priority());
355}
356
357TEST_F(BaseMethodTest, GetPriorityError)
358{
359 EXPECT_CALL(mock, sd_event_source_get_priority(expected_source, testing::_))
360 .WillOnce(Return(-EINVAL));
361 EXPECT_THROW(base->get_priority(), SdEventError);
362}
363
364TEST_F(BaseMethodTest, SetPrioritySuccess)
365{
366 EXPECT_CALL(mock, sd_event_source_set_priority(expected_source, 1024))
367 .WillOnce(Return(0));
368 base->set_priority(1024);
369}
370
371TEST_F(BaseMethodTest, SetPriorityError)
372{
373 EXPECT_CALL(mock, sd_event_source_set_priority(expected_source, 1024))
374 .WillOnce(Return(-EINVAL));
375 EXPECT_THROW(base->set_priority(1024), SdEventError);
376}
377
378TEST_F(BaseMethodTest, GetEnabledSuccess)
379{
380 EXPECT_CALL(mock, sd_event_source_get_enabled(expected_source, testing::_))
381 .WillOnce(DoAll(SetArgPointee<1>(SD_EVENT_ON), Return(0)));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700382 EXPECT_EQ(Enabled::On, base->get_enabled());
William A. Kennington III65db8632018-07-17 14:40:14 -0700383}
384
385TEST_F(BaseMethodTest, GetEnabledError)
386{
387 EXPECT_CALL(mock, sd_event_source_get_enabled(expected_source, testing::_))
388 .WillOnce(Return(-EINVAL));
389 EXPECT_THROW(base->get_enabled(), SdEventError);
390}
391
392TEST_F(BaseMethodTest, SetEnabledSuccess)
393{
394 EXPECT_CALL(mock, sd_event_source_set_enabled(expected_source, SD_EVENT_ON))
395 .WillOnce(Return(0));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700396 base->set_enabled(Enabled::On);
William A. Kennington III65db8632018-07-17 14:40:14 -0700397}
398
399TEST_F(BaseMethodTest, SetEnabledError)
400{
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700401 EXPECT_CALL(mock,
402 sd_event_source_set_enabled(expected_source, SD_EVENT_ONESHOT))
William A. Kennington III65db8632018-07-17 14:40:14 -0700403 .WillOnce(Return(-EINVAL));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -0700404 EXPECT_THROW(base->set_enabled(Enabled::OneShot), SdEventError);
William A. Kennington III0a816c52018-07-17 14:40:14 -0700405}
406
407} // namespace
408} // namespace source
409} // namespace sdeventplus