]> granicus.if.org Git - icinga2/blob - test/base-timer.cpp
Merge pull request #6999 from Icinga/bugfix/compiler-warnings
[icinga2] / test / base-timer.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/timer.hpp"
4 #include "base/utility.hpp"
5 #include "base/application.hpp"
6 #include <BoostTestTargetConfig.h>
7
8 using namespace icinga;
9
10 BOOST_AUTO_TEST_SUITE(base_timer)
11
12 BOOST_AUTO_TEST_CASE(construct)
13 {
14         Timer::Ptr timer = new Timer();
15         BOOST_CHECK(timer);
16 }
17
18 BOOST_AUTO_TEST_CASE(interval)
19 {
20         Timer::Ptr timer = new Timer();
21         timer->SetInterval(1.5);
22         BOOST_CHECK(timer->GetInterval() == 1.5);
23 }
24
25 int counter = 0;
26
27 static void Callback(const Timer::Ptr&)
28 {
29         counter++;
30 }
31
32 BOOST_AUTO_TEST_CASE(invoke)
33 {
34         Timer::Ptr timer = new Timer();
35         timer->OnTimerExpired.connect(&Callback);
36         timer->SetInterval(1);
37
38         counter = 0;
39         timer->Start();
40         Utility::Sleep(5.5);
41         timer->Stop();
42
43         BOOST_CHECK(counter >= 4 && counter <= 6);
44 }
45
46 BOOST_AUTO_TEST_CASE(scope)
47 {
48         Timer::Ptr timer = new Timer();
49         timer->OnTimerExpired.connect(&Callback);
50         timer->SetInterval(1);
51
52         counter = 0;
53         timer->Start();
54         Utility::Sleep(5.5);
55         timer.reset();
56         Utility::Sleep(5.5);
57
58         BOOST_CHECK(counter >= 4 && counter <= 6);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()