blob: 39949c1a6a973f55ff7f0c7f5644cd7be8bb79d9 [file] [log] [blame]
William A. Kennington IIIa4c76ea2022-11-21 16:20:41 -08001#include <sdeventplus/source/event.hpp>
2#include <sdeventplus/utility/sdbus.hpp>
3
Patrick Williamsa8c11e32023-05-10 07:50:56 -05004#include <gtest/gtest.h>
5
William A. Kennington IIIa4c76ea2022-11-21 16:20:41 -08006namespace sdeventplus::utility
7{
8
9struct LoopWithBus : testing::Test
10{
11 Event event = Event::get_new();
12 sdbusplus::bus_t bus = sdbusplus::bus::new_bus();
13};
14
15TEST_F(LoopWithBus, ImmediateExit)
16{
17 event.exit(0);
18 EXPECT_EQ(0, loopWithBus(event, bus));
19}
20
21TEST_F(LoopWithBus, DelayedExit)
22{
23 source::Defer(event, [](source::EventBase& b) {
24 b.get_event().exit(1);
25 }).set_floating(true);
26 EXPECT_EQ(1, loopWithBus(event, bus));
27}
28
29TEST_F(LoopWithBus, ExitSources)
30{
31 int d1 = 0, d2 = 0;
32 source::Exit(event, [&](source::EventBase&) { d1 = 1; }).set_floating(true);
33 source::Defer(event, [&](source::EventBase& b) {
34 source::Exit(event, [&](source::EventBase&) {
35 d2 = 2;
36 }).set_floating(true);
37 b.get_event().exit(3);
38 }).set_floating(true);
39 EXPECT_EQ(3, loopWithBus(event, bus));
40 EXPECT_EQ(1, d1);
41 EXPECT_EQ(2, d2);
42}
43
44} // namespace sdeventplus::utility