Socket/Protocols/Raw: EUI64 documentation
[senf.git] / PPI / Module.test.cc
index 95b2232..2f6df29 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
-    \brief Module.test unit tests */
+    \brief Module unit tests */
 
 //#include "Module.test.hh"
 //#include "Module.test.ih"
 
 // Custom includes
+#include <boost/scoped_ptr.hpp>
+#include "../Utils/membind.hh"
 #include "DebugEvent.hh"
 #include "DebugModules.hh"
 #include "Setup.hh"
@@ -80,6 +82,57 @@ BOOST_AUTO_UNIT_TEST(module)
     BOOST_CHECK( senf::ClockService::now() - tester.time() < senf::ClockService::seconds(1) );
 }
 
+namespace {
+
+    void timeout() {
+        senf::scheduler::terminate();
+    }
+    
+    class InitTest : public ppi::module::Module
+    {
+        SENF_PPI_MODULE(InitTest);
+    public:
+        InitTest() : init (false) {}
+        void v_init() { init = true; }
+
+        bool init;
+    };
+
+    struct MakeInit {
+        boost::scoped_ptr<InitTest> tester;
+        void make() {
+            tester.reset(new InitTest());
+        }
+        void test() {
+            BOOST_REQUIRE( tester );
+            BOOST_CHECK( tester->init );
+        }
+    };
+
+}
+
+BOOST_AUTO_UNIT_TEST(delayedInit)
+{
+    MakeInit maker;
+    senf::scheduler::TimerEvent timer ( 
+        "delayedInit timer",
+        senf::membind(&MakeInit::make, &maker),
+        senf::ClockService::now() + senf::ClockService::milliseconds(250) );
+    senf::scheduler::TimerEvent testTimer (
+        "delayedInit test",
+        senf::membind(&MakeInit::test, &maker),
+        senf::ClockService::now() + senf::ClockService::milliseconds(500) );
+    senf::scheduler::TimerEvent timeoutTimer (
+        "delayedInit timeout",
+        &timeout,
+        senf::ClockService::now() + senf::ClockService::milliseconds(750) );
+
+    senf::ppi::run();
+
+    BOOST_REQUIRE( maker.tester );
+    BOOST_CHECK( maker.tester->init );
+}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_