blob: 868c5e5bfc0dcc50fad982fa9e67933f50cec572 [file] [log] [blame]
Alexander Hansen2cd25e62025-10-23 12:35:39 +02001#pragma once
2
3#include <sdbusplus/timer.hpp>
4
5#include <gtest/gtest.h>
6
7using sdbusplus::Timer;
8
9class TimerTest : public ::testing::Test
10{
11 public:
12 // systemd event handler
13 sd_event* events = nullptr;
14
15 // Need this so that events can be initialized.
16 int rc;
17
18 // Source of event
19 sd_event_source* eventSource = nullptr;
20
21 // Add a Timer Object
22 Timer timer;
23
24 // Gets called as part of each TEST_F construction
25 TimerTest() : rc(sd_event_default(&events)), timer(events)
26 {
27 // Check for successful creation of
28 // event handler and timer object.
29 EXPECT_GE(rc, 0);
30 }
31
32 // Gets called as part of each TEST_F destruction
33 ~TimerTest() override
34 {
35 events = sd_event_unref(events);
36 }
37};
38
39class TimerTestCallBack : public ::testing::Test
40{
41 public:
42 // systemd event handler
43 sd_event* events;
44
45 // Need this so that events can be initialized.
46 int rc;
47
48 // Source of event
49 sd_event_source* eventSource = nullptr;
50
51 // Add a Timer Object
52 std::unique_ptr<Timer> timer = nullptr;
53
54 // Indicates optional call back fun was called
55 bool callBackDone = false;
56
57 void callBack()
58 {
59 callBackDone = true;
60 }
61
62 // Gets called as part of each TEST_F construction
63 TimerTestCallBack() : rc(sd_event_default(&events))
64
65 {
66 // Check for successful creation of
67 // event handler and timer object.
68 EXPECT_GE(rc, 0);
69
70 std::function<void()> func(
71 std::bind(&TimerTestCallBack::callBack, this));
72 timer = std::make_unique<Timer>(events, func);
73 }
74
75 // Gets called as part of each TEST_F destruction
76 ~TimerTestCallBack() override
77 {
78 events = sd_event_unref(events);
79 }
80};