fixes for g++ 4.5 (some members returned "the constructor, not the type")
[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.test non-inline non-template implementation */
25
26 //#include "TimerEventProxy.test.hh"
27 //#include "TimerEventProxy.test.ih"
28
29 // Custom includes
30 #include "TimerEventProxy.hh"
31 #include "Scheduler.hh"
32
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
35 #include <boost/random.hpp>
36
37 #define prefix_
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 using namespace senf;
40
41 namespace {
42
43     int mask = 0;
44
45     void handler(ClockService::clock_type time, int const &id)
46     {
47         mask = mask + id;
48     }
49
50     void run(ClockService::clock_type t) {
51         scheduler::TimerEvent timeout(
52                 "test-timeout", &scheduler::terminate, scheduler::now() + t);
53         scheduler::process();
54     }
55
56 }
57
58 SENF_AUTO_UNIT_TEST(timerEventProxy)
59 {
60 //    // abort on watchdog timeout
61 //    scheduler::watchdogAbort( true);
62 //    scheduler::watchdogTimeout(5000);
63
64     ClockService::clock_type now (ClockService::now());
65     {
66         scheduler::TimerEventProxy<int> timers ("unit-test");
67
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);
75
76         BOOST_CHECK_EQUAL( timers.timeout(1), now + ClockService::milliseconds(200));
77         BOOST_CHECK_EQUAL( timers.timeout(2), now + ClockService::milliseconds(700));
78
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);
82
83         run( ClockService::milliseconds( 2000));
84
85         BOOST_CHECK( mask == 7);
86     }
87 }
88
89
90 //-/////////////////////////////////////////////////////////////////////////////////////////////////
91 #undef prefix_
92
93
94 // Local Variables:
95 // mode: c++
96 // fill-column: 100
97 // comment-column: 40
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // End: