fixes for g++ 4.5 (some members returned "the constructor, not the type")
[senf.git] / senf / Scheduler / TimerEventProxy.test.cc
index eb07187..7b9c8a9 100644 (file)
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
- \brief TimerEventProxy public header */
-//
-
-/** \file
     \brief TimerEventProxy.test non-inline non-template implementation */
 
 //#include "TimerEventProxy.test.hh"
 // Custom includes
 #include "TimerEventProxy.hh"
 #include "Scheduler.hh"
-#include <boost/bind.hpp>
 
 #include <senf/Utils/auto_unit_test.hh>
 #include <boost/test/test_tools.hpp>
 #include <boost/random.hpp>
 
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
+using namespace senf;
+
 namespace {
 
-    int count = 0;
+    int mask = 0;
 
-    void handler( senf::ClockService::clock_type time, int const &id)
+    void handler(ClockService::clock_type time, int const &id)
     {
-        std::cerr << "TimerEventProxy handler count="<<count<<" id="<<id<<"\n";
-        ++count;
+        mask = mask + id;
     }
 
-    void myexit(){
-        std::cerr << "TimerEventProxy terminating\n";
-        senf::scheduler::terminate();
+    void run(ClockService::clock_type t) {
+        scheduler::TimerEvent timeout(
+                "test-timeout", &scheduler::terminate, scheduler::now() + t);
+        scheduler::process();
     }
 
 }
 
 SENF_AUTO_UNIT_TEST(timerEventProxy)
 {
-
 //    // abort on watchdog timeout
-//    senf::scheduler::watchdogAbort( true);
-//    senf::scheduler::watchdogTimeout(5000);
+//    scheduler::watchdogAbort( true);
+//    scheduler::watchdogTimeout(5000);
 
-    senf::ClockService::clock_type t (senf::ClockService::now());
+    ClockService::clock_type now (ClockService::now());
     {
-        senf::scheduler::TimerEventProxy<int> timers;
+        scheduler::TimerEventProxy<int> timers ("unit-test");
+
+//        timers.add( t + ClockService::milliseconds(10000), 0 , &handler);
+        timers.add( now + ClockService::milliseconds(800), 4, &handler);
+        timers.add( now + ClockService::milliseconds(200), 1, &handler);
+        BOOST_CHECK( timers.remove( 4));
+        BOOST_CHECK(! timers.remove( 4));
+        BOOST_CHECK_EQUAL( timers.timeout(4), 0);
+        timers.add( now + ClockService::milliseconds(700), 2, &handler);
 
-        SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(10000), 0 , &handler));
-        SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(800), 3, &handler));
-        SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(200), 1, &handler));
-        SENF_CHECK_NO_THROW( timers.del( 3));
-        SENF_CHECK_NO_THROW( timers.add( t + senf::ClockService::milliseconds(700), 2, &handler));
+        BOOST_CHECK_EQUAL( timers.timeout(1), now + ClockService::milliseconds(200));
+        BOOST_CHECK_EQUAL( timers.timeout(2), now + ClockService::milliseconds(700));
 
-        // set timeout for termination
-        senf::scheduler::TimerEvent te_exit( "myexit", &myexit, t + senf::ClockService::milliseconds( 1000));
+        timers.add( now + ClockService::milliseconds(800), 2, &handler);
+        BOOST_CHECK_EQUAL( timers.timeout(2), now + ClockService::milliseconds(800));
+        timers.add( now, 4, &handler);
 
-        SENF_CHECK_NO_THROW( senf::scheduler::process() );
+        run( ClockService::milliseconds( 2000));
 
-        BOOST_CHECK( count == 2);
+        BOOST_CHECK( mask == 7);
     }
 }
 
 
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_