blob: 29ab72ba53cb4afbb1cda969d2353a6882fcec5f [file] [log] [blame]
Alexander Hansen2cd25e62025-10-23 12:35:39 +02001#include "suite.hpp"
2
3#include <sdbusplus/timer.hpp>
4
5#include <chrono>
6
7#include <gtest/gtest.h>
8
9/** @brief Makes sure that optional callback is called */
10TEST_F(TimerTestCallBack, optionalFuncCallBackDone)
11{
12 using namespace std::chrono;
13
14 auto time = duration_cast<microseconds>(seconds(2));
15 EXPECT_GE(timer->start(time), 0);
16
17 // Waiting 2 seconds is enough here since we have
18 // already spent some usec now
19 int count = 0;
20 while (count < 2 && !timer->isExpired())
21 {
22 // Returns -0- on timeout and positive number on dispatch
23 auto sleepTime = duration_cast<microseconds>(seconds(1));
24 if (!sd_event_run(events, sleepTime.count()))
25 {
26 count++;
27 }
28 }
29 EXPECT_EQ(true, timer->isExpired());
30 EXPECT_EQ(true, callBackDone);
31 EXPECT_EQ(1, count);
32}