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