4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Jens Moedeker <jens.moedeker@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief TimerEventProxy.test non-inline non-template implementation */
26 //#include "TimerEventProxy.test.hh"
27 //#include "TimerEventProxy.test.ih"
30 #include "TimerEventProxy.hh"
31 #include "Scheduler.hh"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
35 #include <boost/random.hpp>
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 void handler(ClockService::clock_type time, int const &id)
50 void run(ClockService::clock_type t) {
51 scheduler::TimerEvent timeout(
52 "test-timeout", &scheduler::terminate, scheduler::now() + t);
58 SENF_AUTO_UNIT_TEST(timerEventProxy)
60 // // abort on watchdog timeout
61 // scheduler::watchdogAbort( true);
62 // scheduler::watchdogTimeout(5000);
64 ClockService::clock_type now (ClockService::now());
66 scheduler::TimerEventProxy<int> timers ("unit-test");
68 // timers.add( t + ClockService::milliseconds(10000), 0 , &handler);
69 timers.add( now + ClockService::milliseconds(800), 4, &handler);
70 timers.add( now + ClockService::milliseconds(200), 1, &handler);
71 BOOST_CHECK( timers.remove( 4));
72 BOOST_CHECK(! timers.remove( 4));
73 BOOST_CHECK_EQUAL( timers.timeout(4), 0);
74 timers.add( now + ClockService::milliseconds(700), 2, &handler);
76 BOOST_CHECK_EQUAL( timers.timeout(1), now + ClockService::milliseconds(200));
77 BOOST_CHECK_EQUAL( timers.timeout(2), now + ClockService::milliseconds(700));
79 timers.add( now + ClockService::milliseconds(800), 2, &handler);
80 BOOST_CHECK_EQUAL( timers.timeout(2), now + ClockService::milliseconds(800));
81 timers.add( now, 4, &handler);
83 run( ClockService::milliseconds( 2000));
85 BOOST_CHECK( mask == 7);
90 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"