new timer event proxy to reduce scheduler load
[senf.git] / senf / Scheduler / TimerEventProxy.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2010
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>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24  \brief TimerEventProxy public header */
25 //
26
27 /** \file
28     \brief TimerEventProxy.test non-inline non-template implementation */
29
30 //#include "TimerEventProxy.test.hh"
31 //#include "TimerEventProxy.test.ih"
32
33 // Custom includes
34 #include "TimerEventProxy.hh"
35 #include "Scheduler.hh"
36 #include <boost/bind.hpp>
37
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
40 #include <boost/random.hpp>
41
42 #define prefix_
43 ///////////////////////////////cc.p////////////////////////////////////////
44 namespace {
45
46     int count = 0;
47
48     void handler( senf::ClockService::clock_type time, int const &id)
49     {
50         std::cerr << "TimerEventProxy handler count="<<count<<" id="<<id<<"\n";
51         ++count;
52     }
53
54     void myexit(){
55         std::cerr << "TimerEventProxy terminating\n";
56         senf::scheduler::terminate();
57     }
58
59 }
60
61 SENF_AUTO_UNIT_TEST(timerEventProxy)
62 {
63
64 //    // abort on watchdog timeout
65 //    senf::scheduler::watchdogAbort( true);
66 //    senf::scheduler::watchdogTimeout(5000);
67
68     senf::ClockService::clock_type t (senf::ClockService::now());
69     {
70         senf::scheduler::TimerEventProxy<int> timers;
71
72         SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(10000), 0 , &handler));
73         SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(800), 3, &handler));
74         SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(200), 1, &handler));
75         SENF_CHECK_NO_THROW( timers.del( 3));
76         SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(700), 2, &handler));
77
78         // set timeout for termination
79         senf::scheduler::TimerEvent te_exit( "myexit", &myexit, t + senf::ClockService::milliseconds( 1000));
80
81         SENF_CHECK_NO_THROW( senf::scheduler::process() );
82
83         BOOST_CHECK( count == 2);
84     }
85 }
86
87
88 ///////////////////////////////cc.e////////////////////////////////////////
89 #undef prefix_
90
91
92 // Local Variables:
93 // mode: c++
94 // fill-column: 100
95 // comment-column: 40
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // End: