1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "base/timer.h"
21 #include "base/utility.h"
22 #include "base/application.h"
23 #include <boost/test/unit_test.hpp>
24 #include <boost/foreach.hpp>
26 using namespace icinga;
37 Timer::Uninitialize();
41 BOOST_FIXTURE_TEST_SUITE(base_timer, TimerFixture)
43 BOOST_AUTO_TEST_CASE(construct)
45 Timer::Ptr timer = make_shared<Timer>();
49 BOOST_AUTO_TEST_CASE(interval)
51 Timer::Ptr timer = make_shared<Timer>();
52 timer->SetInterval(1.5);
53 BOOST_CHECK(timer->GetInterval() == 1.5);
56 static void Callback(int *counter)
61 BOOST_AUTO_TEST_CASE(invoke)
64 Timer::Ptr timer = make_shared<Timer>();
65 timer->OnTimerExpired.connect(boost::bind(&Callback, &counter));
66 timer->SetInterval(1);
73 BOOST_CHECK(counter >= 4 && counter <= 6);
76 BOOST_AUTO_TEST_CASE(scope)
79 Timer::Ptr timer = make_shared<Timer>();
80 timer->OnTimerExpired.connect(boost::bind(&Callback, &counter));
81 timer->SetInterval(1);
89 BOOST_CHECK(counter >= 4 && counter <= 6);
92 BOOST_AUTO_TEST_SUITE_END()