merge
authorPavel Boyko <boyko@iitp.ru>
Wed, 30 Sep 2009 20:15:49 +0400
changeset 5709 104026defae5
parent 5708 55abd6e61f17 (current diff)
parent 5321 4e0214eefe4e (diff)
child 5710 802e547277d0
merge
src/core/traced-callback.cc
--- a/bindings/python/apidefs/gcc-ILP32/ns3_module_core.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_core.py	Wed Sep 30 20:15:49 2009 +0400
@@ -589,8 +589,8 @@
                    'void', 
                    [param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')], 
                    is_static=True)
-    ## names.h: static void ns3::Names::Delete() [member function]
-    cls.add_method('Delete', 
+    ## names.h: static void ns3::Names::Clear() [member function]
+    cls.add_method('Clear', 
                    'void', 
                    [], 
                    is_static=True)
--- a/bindings/python/apidefs/gcc-ILP32/ns3_module_node.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_node.py	Wed Sep 30 20:15:49 2009 +0400
@@ -11,6 +11,8 @@
     module.add_class('Address')
     ## address.h: ns3::Address::MaxSize_e [enumeration]
     module.add_enum('MaxSize_e', ['MAX_SIZE'], outer_class=root_module['ns3::Address'])
+    ## channel-list.h: ns3::ChannelList [class]
+    module.add_class('ChannelList')
     ## inet6-socket-address.h: ns3::Inet6SocketAddress [class]
     module.add_class('Inet6SocketAddress')
     ## inet6-socket-address.h: ns3::Inet6SocketAddress [class]
@@ -253,6 +255,7 @@
 
 def register_methods(root_module):
     register_Ns3Address_methods(root_module, root_module['ns3::Address'])
+    register_Ns3ChannelList_methods(root_module, root_module['ns3::ChannelList'])
     register_Ns3Inet6SocketAddress_methods(root_module, root_module['ns3::Inet6SocketAddress'])
     register_Ns3InetSocketAddress_methods(root_module, root_module['ns3::InetSocketAddress'])
     register_Ns3Ipv4Address_methods(root_module, root_module['ns3::Ipv4Address'])
@@ -394,6 +397,38 @@
                    is_const=True)
     return
 
+def register_Ns3ChannelList_methods(root_module, cls):
+    ## channel-list.h: ns3::ChannelList::ChannelList() [constructor]
+    cls.add_constructor([])
+    ## channel-list.h: ns3::ChannelList::ChannelList(ns3::ChannelList const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::ChannelList const &', 'arg0')])
+    ## channel-list.h: static uint32_t ns3::ChannelList::Add(ns3::Ptr<ns3::Channel> channel) [member function]
+    cls.add_method('Add', 
+                   'uint32_t', 
+                   [param('ns3::Ptr< ns3::Channel >', 'channel')], 
+                   is_static=True)
+    ## channel-list.h: static __gnu_cxx::__normal_iterator<const ns3::Ptr<ns3::Channel>*,std::vector<ns3::Ptr<ns3::Channel>, std::allocator<ns3::Ptr<ns3::Channel> > > > ns3::ChannelList::Begin() [member function]
+    cls.add_method('Begin', 
+                   '__gnu_cxx::__normal_iterator< ns3::Ptr< ns3::Channel > const, std::vector< ns3::Ptr< ns3::Channel > > >', 
+                   [], 
+                   is_static=True)
+    ## channel-list.h: static __gnu_cxx::__normal_iterator<const ns3::Ptr<ns3::Channel>*,std::vector<ns3::Ptr<ns3::Channel>, std::allocator<ns3::Ptr<ns3::Channel> > > > ns3::ChannelList::End() [member function]
+    cls.add_method('End', 
+                   '__gnu_cxx::__normal_iterator< ns3::Ptr< ns3::Channel > const, std::vector< ns3::Ptr< ns3::Channel > > >', 
+                   [], 
+                   is_static=True)
+    ## channel-list.h: static ns3::Ptr<ns3::Channel> ns3::ChannelList::GetChannel(uint32_t n) [member function]
+    cls.add_method('GetChannel', 
+                   'ns3::Ptr< ns3::Channel >', 
+                   [param('uint32_t', 'n')], 
+                   is_static=True)
+    ## channel-list.h: static uint32_t ns3::ChannelList::GetNChannels() [member function]
+    cls.add_method('GetNChannels', 
+                   'uint32_t', 
+                   [], 
+                   is_static=True)
+    return
+
 def register_Ns3Inet6SocketAddress_methods(root_module, cls):
     ## inet6-socket-address.h: ns3::Inet6SocketAddress::Inet6SocketAddress(ns3::Inet6SocketAddress const & arg0) [copy constructor]
     cls.add_constructor([param('ns3::Inet6SocketAddress const &', 'arg0')])
@@ -1557,10 +1592,10 @@
 def register_Ns3PbbAddressTlvBlock_methods(root_module, cls):
     cls.add_binary_comparison_operator('==')
     cls.add_binary_comparison_operator('!=')
+    ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock(ns3::PbbAddressTlvBlock const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::PbbAddressTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock() [constructor]
     cls.add_constructor([])
-    ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock(ns3::PbbAddressTlvBlock const & arg0) [copy constructor]
-    cls.add_constructor([param('ns3::PbbAddressTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::Ptr<ns3::PbbAddressTlv> ns3::PbbAddressTlvBlock::Back() const [member function]
     cls.add_method('Back', 
                    'ns3::Ptr< ns3::PbbAddressTlv >', 
@@ -2134,10 +2169,10 @@
 def register_Ns3PbbTlvBlock_methods(root_module, cls):
     cls.add_binary_comparison_operator('==')
     cls.add_binary_comparison_operator('!=')
+    ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock(ns3::PbbTlvBlock const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::PbbTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock() [constructor]
     cls.add_constructor([])
-    ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock(ns3::PbbTlvBlock const & arg0) [copy constructor]
-    cls.add_constructor([param('ns3::PbbTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::Ptr<ns3::PbbTlv> ns3::PbbTlvBlock::Back() const [member function]
     cls.add_method('Back', 
                    'ns3::Ptr< ns3::PbbTlv >', 
@@ -3908,6 +3943,11 @@
                    'ns3::Ptr< ns3::NetDevice >', 
                    [param('uint32_t', 'i')], 
                    is_pure_virtual=True, is_const=True, is_virtual=True)
+    ## channel.h: uint32_t ns3::Channel::GetId() const [member function]
+    cls.add_method('GetId', 
+                   'uint32_t', 
+                   [], 
+                   is_const=True)
     ## channel.h: uint32_t ns3::Channel::GetNDevices() const [member function]
     cls.add_method('GetNDevices', 
                    'uint32_t', 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/python/apidefs/gcc-ILP32/ns3_module_test.py	Wed Sep 30 20:15:49 2009 +0400
@@ -0,0 +1,111 @@
+from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers
+
+def register_types(module):
+    root_module = module.get_root()
+    
+    
+    ## Register a nested module for the namespace Config
+    
+    nested_module = module.add_cpp_namespace('Config')
+    register_types_ns3_Config(nested_module)
+    
+    
+    ## Register a nested module for the namespace TimeStepPrecision
+    
+    nested_module = module.add_cpp_namespace('TimeStepPrecision')
+    register_types_ns3_TimeStepPrecision(nested_module)
+    
+    
+    ## Register a nested module for the namespace addressUtils
+    
+    nested_module = module.add_cpp_namespace('addressUtils')
+    register_types_ns3_addressUtils(nested_module)
+    
+    
+    ## Register a nested module for the namespace dot11s
+    
+    nested_module = module.add_cpp_namespace('dot11s')
+    register_types_ns3_dot11s(nested_module)
+    
+    
+    ## Register a nested module for the namespace flame
+    
+    nested_module = module.add_cpp_namespace('flame')
+    register_types_ns3_flame(nested_module)
+    
+    
+    ## Register a nested module for the namespace internal
+    
+    nested_module = module.add_cpp_namespace('internal')
+    register_types_ns3_internal(nested_module)
+    
+    
+    ## Register a nested module for the namespace olsr
+    
+    nested_module = module.add_cpp_namespace('olsr')
+    register_types_ns3_olsr(nested_module)
+    
+
+def register_types_ns3_Config(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_TimeStepPrecision(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_addressUtils(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_dot11s(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_flame(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_internal(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_olsr(module):
+    root_module = module.get_root()
+    
+
+def register_methods(root_module):
+    return
+
+def register_functions(root_module):
+    module = root_module
+    register_functions_ns3_Config(module.get_submodule('Config'), root_module)
+    register_functions_ns3_TimeStepPrecision(module.get_submodule('TimeStepPrecision'), root_module)
+    register_functions_ns3_addressUtils(module.get_submodule('addressUtils'), root_module)
+    register_functions_ns3_dot11s(module.get_submodule('dot11s'), root_module)
+    register_functions_ns3_flame(module.get_submodule('flame'), root_module)
+    register_functions_ns3_internal(module.get_submodule('internal'), root_module)
+    register_functions_ns3_olsr(module.get_submodule('olsr'), root_module)
+    return
+
+def register_functions_ns3_Config(module, root_module):
+    return
+
+def register_functions_ns3_TimeStepPrecision(module, root_module):
+    return
+
+def register_functions_ns3_addressUtils(module, root_module):
+    return
+
+def register_functions_ns3_dot11s(module, root_module):
+    return
+
+def register_functions_ns3_flame(module, root_module):
+    return
+
+def register_functions_ns3_internal(module, root_module):
+    return
+
+def register_functions_ns3_olsr(module, root_module):
+    return
+
--- a/bindings/python/apidefs/gcc-ILP32/ns3modulegen_generated.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-ILP32/ns3modulegen_generated.py	Wed Sep 30 20:15:49 2009 +0400
@@ -14,6 +14,7 @@
 import sys
 import ns3_module_core
 import ns3_module_simulator
+import ns3_module_test
 import ns3_module_mobility
 import ns3_module_common
 import ns3_module_node
@@ -73,6 +74,17 @@
         ns3_module_simulator__local.register_types(module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_types(module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_types(module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_types(module)
     
@@ -504,6 +516,17 @@
         ns3_module_simulator__local.register_methods(root_module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_methods(root_module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_methods(root_module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_methods(root_module)
     
@@ -985,6 +1008,17 @@
         ns3_module_simulator__local.register_functions(root_module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_functions(root_module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_functions(root_module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_functions(root_module)
     
--- a/bindings/python/apidefs/gcc-LP64/ns3_module_core.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-LP64/ns3_module_core.py	Wed Sep 30 20:15:49 2009 +0400
@@ -589,8 +589,8 @@
                    'void', 
                    [param('ns3::Ptr< ns3::Object >', 'context'), param('std::string', 'name'), param('ns3::Ptr< ns3::Object >', 'object')], 
                    is_static=True)
-    ## names.h: static void ns3::Names::Delete() [member function]
-    cls.add_method('Delete', 
+    ## names.h: static void ns3::Names::Clear() [member function]
+    cls.add_method('Clear', 
                    'void', 
                    [], 
                    is_static=True)
--- a/bindings/python/apidefs/gcc-LP64/ns3_module_node.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-LP64/ns3_module_node.py	Wed Sep 30 20:15:49 2009 +0400
@@ -11,6 +11,8 @@
     module.add_class('Address')
     ## address.h: ns3::Address::MaxSize_e [enumeration]
     module.add_enum('MaxSize_e', ['MAX_SIZE'], outer_class=root_module['ns3::Address'])
+    ## channel-list.h: ns3::ChannelList [class]
+    module.add_class('ChannelList')
     ## inet6-socket-address.h: ns3::Inet6SocketAddress [class]
     module.add_class('Inet6SocketAddress')
     ## inet6-socket-address.h: ns3::Inet6SocketAddress [class]
@@ -253,6 +255,7 @@
 
 def register_methods(root_module):
     register_Ns3Address_methods(root_module, root_module['ns3::Address'])
+    register_Ns3ChannelList_methods(root_module, root_module['ns3::ChannelList'])
     register_Ns3Inet6SocketAddress_methods(root_module, root_module['ns3::Inet6SocketAddress'])
     register_Ns3InetSocketAddress_methods(root_module, root_module['ns3::InetSocketAddress'])
     register_Ns3Ipv4Address_methods(root_module, root_module['ns3::Ipv4Address'])
@@ -394,6 +397,38 @@
                    is_const=True)
     return
 
+def register_Ns3ChannelList_methods(root_module, cls):
+    ## channel-list.h: ns3::ChannelList::ChannelList() [constructor]
+    cls.add_constructor([])
+    ## channel-list.h: ns3::ChannelList::ChannelList(ns3::ChannelList const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::ChannelList const &', 'arg0')])
+    ## channel-list.h: static uint32_t ns3::ChannelList::Add(ns3::Ptr<ns3::Channel> channel) [member function]
+    cls.add_method('Add', 
+                   'uint32_t', 
+                   [param('ns3::Ptr< ns3::Channel >', 'channel')], 
+                   is_static=True)
+    ## channel-list.h: static __gnu_cxx::__normal_iterator<const ns3::Ptr<ns3::Channel>*,std::vector<ns3::Ptr<ns3::Channel>, std::allocator<ns3::Ptr<ns3::Channel> > > > ns3::ChannelList::Begin() [member function]
+    cls.add_method('Begin', 
+                   '__gnu_cxx::__normal_iterator< ns3::Ptr< ns3::Channel > const, std::vector< ns3::Ptr< ns3::Channel > > >', 
+                   [], 
+                   is_static=True)
+    ## channel-list.h: static __gnu_cxx::__normal_iterator<const ns3::Ptr<ns3::Channel>*,std::vector<ns3::Ptr<ns3::Channel>, std::allocator<ns3::Ptr<ns3::Channel> > > > ns3::ChannelList::End() [member function]
+    cls.add_method('End', 
+                   '__gnu_cxx::__normal_iterator< ns3::Ptr< ns3::Channel > const, std::vector< ns3::Ptr< ns3::Channel > > >', 
+                   [], 
+                   is_static=True)
+    ## channel-list.h: static ns3::Ptr<ns3::Channel> ns3::ChannelList::GetChannel(uint32_t n) [member function]
+    cls.add_method('GetChannel', 
+                   'ns3::Ptr< ns3::Channel >', 
+                   [param('uint32_t', 'n')], 
+                   is_static=True)
+    ## channel-list.h: static uint32_t ns3::ChannelList::GetNChannels() [member function]
+    cls.add_method('GetNChannels', 
+                   'uint32_t', 
+                   [], 
+                   is_static=True)
+    return
+
 def register_Ns3Inet6SocketAddress_methods(root_module, cls):
     ## inet6-socket-address.h: ns3::Inet6SocketAddress::Inet6SocketAddress(ns3::Inet6SocketAddress const & arg0) [copy constructor]
     cls.add_constructor([param('ns3::Inet6SocketAddress const &', 'arg0')])
@@ -1557,10 +1592,10 @@
 def register_Ns3PbbAddressTlvBlock_methods(root_module, cls):
     cls.add_binary_comparison_operator('==')
     cls.add_binary_comparison_operator('!=')
+    ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock(ns3::PbbAddressTlvBlock const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::PbbAddressTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock() [constructor]
     cls.add_constructor([])
-    ## packetbb.h: ns3::PbbAddressTlvBlock::PbbAddressTlvBlock(ns3::PbbAddressTlvBlock const & arg0) [copy constructor]
-    cls.add_constructor([param('ns3::PbbAddressTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::Ptr<ns3::PbbAddressTlv> ns3::PbbAddressTlvBlock::Back() const [member function]
     cls.add_method('Back', 
                    'ns3::Ptr< ns3::PbbAddressTlv >', 
@@ -2134,10 +2169,10 @@
 def register_Ns3PbbTlvBlock_methods(root_module, cls):
     cls.add_binary_comparison_operator('==')
     cls.add_binary_comparison_operator('!=')
+    ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock(ns3::PbbTlvBlock const & arg0) [copy constructor]
+    cls.add_constructor([param('ns3::PbbTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock() [constructor]
     cls.add_constructor([])
-    ## packetbb.h: ns3::PbbTlvBlock::PbbTlvBlock(ns3::PbbTlvBlock const & arg0) [copy constructor]
-    cls.add_constructor([param('ns3::PbbTlvBlock const &', 'arg0')])
     ## packetbb.h: ns3::Ptr<ns3::PbbTlv> ns3::PbbTlvBlock::Back() const [member function]
     cls.add_method('Back', 
                    'ns3::Ptr< ns3::PbbTlv >', 
@@ -3908,6 +3943,11 @@
                    'ns3::Ptr< ns3::NetDevice >', 
                    [param('uint32_t', 'i')], 
                    is_pure_virtual=True, is_const=True, is_virtual=True)
+    ## channel.h: uint32_t ns3::Channel::GetId() const [member function]
+    cls.add_method('GetId', 
+                   'uint32_t', 
+                   [], 
+                   is_const=True)
     ## channel.h: uint32_t ns3::Channel::GetNDevices() const [member function]
     cls.add_method('GetNDevices', 
                    'uint32_t', 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/python/apidefs/gcc-LP64/ns3_module_test.py	Wed Sep 30 20:15:49 2009 +0400
@@ -0,0 +1,111 @@
+from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers
+
+def register_types(module):
+    root_module = module.get_root()
+    
+    
+    ## Register a nested module for the namespace Config
+    
+    nested_module = module.add_cpp_namespace('Config')
+    register_types_ns3_Config(nested_module)
+    
+    
+    ## Register a nested module for the namespace TimeStepPrecision
+    
+    nested_module = module.add_cpp_namespace('TimeStepPrecision')
+    register_types_ns3_TimeStepPrecision(nested_module)
+    
+    
+    ## Register a nested module for the namespace addressUtils
+    
+    nested_module = module.add_cpp_namespace('addressUtils')
+    register_types_ns3_addressUtils(nested_module)
+    
+    
+    ## Register a nested module for the namespace dot11s
+    
+    nested_module = module.add_cpp_namespace('dot11s')
+    register_types_ns3_dot11s(nested_module)
+    
+    
+    ## Register a nested module for the namespace flame
+    
+    nested_module = module.add_cpp_namespace('flame')
+    register_types_ns3_flame(nested_module)
+    
+    
+    ## Register a nested module for the namespace internal
+    
+    nested_module = module.add_cpp_namespace('internal')
+    register_types_ns3_internal(nested_module)
+    
+    
+    ## Register a nested module for the namespace olsr
+    
+    nested_module = module.add_cpp_namespace('olsr')
+    register_types_ns3_olsr(nested_module)
+    
+
+def register_types_ns3_Config(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_TimeStepPrecision(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_addressUtils(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_dot11s(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_flame(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_internal(module):
+    root_module = module.get_root()
+    
+
+def register_types_ns3_olsr(module):
+    root_module = module.get_root()
+    
+
+def register_methods(root_module):
+    return
+
+def register_functions(root_module):
+    module = root_module
+    register_functions_ns3_Config(module.get_submodule('Config'), root_module)
+    register_functions_ns3_TimeStepPrecision(module.get_submodule('TimeStepPrecision'), root_module)
+    register_functions_ns3_addressUtils(module.get_submodule('addressUtils'), root_module)
+    register_functions_ns3_dot11s(module.get_submodule('dot11s'), root_module)
+    register_functions_ns3_flame(module.get_submodule('flame'), root_module)
+    register_functions_ns3_internal(module.get_submodule('internal'), root_module)
+    register_functions_ns3_olsr(module.get_submodule('olsr'), root_module)
+    return
+
+def register_functions_ns3_Config(module, root_module):
+    return
+
+def register_functions_ns3_TimeStepPrecision(module, root_module):
+    return
+
+def register_functions_ns3_addressUtils(module, root_module):
+    return
+
+def register_functions_ns3_dot11s(module, root_module):
+    return
+
+def register_functions_ns3_flame(module, root_module):
+    return
+
+def register_functions_ns3_internal(module, root_module):
+    return
+
+def register_functions_ns3_olsr(module, root_module):
+    return
+
--- a/bindings/python/apidefs/gcc-LP64/ns3modulegen_generated.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/bindings/python/apidefs/gcc-LP64/ns3modulegen_generated.py	Wed Sep 30 20:15:49 2009 +0400
@@ -14,6 +14,7 @@
 import sys
 import ns3_module_core
 import ns3_module_simulator
+import ns3_module_test
 import ns3_module_mobility
 import ns3_module_common
 import ns3_module_node
@@ -73,6 +74,17 @@
         ns3_module_simulator__local.register_types(module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_types(module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_types(module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_types(module)
     
@@ -504,6 +516,17 @@
         ns3_module_simulator__local.register_methods(root_module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_methods(root_module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_methods(root_module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_methods(root_module)
     
@@ -985,6 +1008,17 @@
         ns3_module_simulator__local.register_functions(root_module)
     
     root_module.end_section('ns3_module_simulator')
+    root_module.begin_section('ns3_module_test')
+    ns3_module_test.register_functions(root_module)
+    
+    try:
+        import ns3_module_test__local
+    except ImportError:
+        pass
+    else:
+        ns3_module_test__local.register_functions(root_module)
+    
+    root_module.end_section('ns3_module_test')
     root_module.begin_section('ns3_module_mobility')
     ns3_module_mobility.register_functions(root_module)
     
--- a/src/applications/udp-echo/udp-echo-client.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/applications/udp-echo/udp-echo-client.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -130,6 +130,7 @@
     {
       m_socket->Close ();
       m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket> > ());
+      m_socket = 0;
     }
 
   Simulator::Cancel(m_sendEvent);
--- a/src/contrib/event-garbage-collector.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/contrib/event-garbage-collector.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -84,17 +84,14 @@
     }
 }
 
-}; // namespace ns3
-
+} // namespace ns3
 
 
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class EventGarbageCollectorTests : public Test
+class EventGarbageCollectorTestCase : public TestCase
 {
   int m_counter;
   EventGarbageCollector *m_events;
@@ -103,20 +100,20 @@
 
 public:
 
-  EventGarbageCollectorTests ();
-  virtual ~EventGarbageCollectorTests ();
-  virtual bool RunTests (void);
+  EventGarbageCollectorTestCase ();
+  virtual ~EventGarbageCollectorTestCase ();
+  virtual bool DoRun (void);
 };
 
-EventGarbageCollectorTests::EventGarbageCollectorTests ()
-  : Test ("EventGarbageCollector"), m_counter (0), m_events (0)
+EventGarbageCollectorTestCase::EventGarbageCollectorTestCase ()
+  : TestCase ("EventGarbageCollector"), m_counter (0), m_events (0)
 {}
 
-EventGarbageCollectorTests::~EventGarbageCollectorTests ()
+EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase ()
 {}
 
 void
-EventGarbageCollectorTests::EventGarbageCollectorCallback ()
+EventGarbageCollectorTestCase::EventGarbageCollectorCallback ()
 {
   m_counter++;
   if (m_counter == 50)
@@ -127,27 +124,33 @@
     }
 }
 
-bool EventGarbageCollectorTests::RunTests (void)
+bool EventGarbageCollectorTestCase::DoRun (void)
 {
-  bool result = true;
-
   m_events = new EventGarbageCollector ();
 
   for (int n = 0; n < 100; n++)
     {
       m_events->Track (Simulator::Schedule
                        (Simulator::Now (),
-                        &EventGarbageCollectorTests::EventGarbageCollectorCallback,
+                        &EventGarbageCollectorTestCase::EventGarbageCollectorCallback,
                         this));
     }
   Simulator::Run ();
-  NS_TEST_ASSERT_EQUAL (m_events, 0);
-  NS_TEST_ASSERT_EQUAL (m_counter, 50);
-  return result;
+  NS_TEST_EXPECT_MSG_EQ (m_events, 0, "");
+  NS_TEST_EXPECT_MSG_EQ (m_counter, 50, "");
+
+  return false;
 }
 
-static EventGarbageCollectorTests g_eventCollectorTests;
+static class EventGarbageCollectorTestSuite : public TestSuite
+{
+public:
+  EventGarbageCollectorTestSuite ()
+    : TestSuite ("event-garbage-collector", UNIT) 
+  {
+    AddTestCase (new EventGarbageCollectorTestCase ());
+  }
+} g_eventGarbageCollectorTests;
     
-};
+}
 
-#endif /* RUN_SELF_TESTS */
--- a/src/contrib/flow-monitor/histogram.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/contrib/flow-monitor/histogram.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -148,65 +148,67 @@
 } // namespace ns3
 
 
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class HistogramTest : public ns3::Test {
+class HistogramTestCase : public ns3::TestCase {
 private:
 public:
-  HistogramTest ();
-  virtual bool RunTests (void);
+  HistogramTestCase ();
+  virtual bool DoRun (void);
 
 
 };
 
-HistogramTest::HistogramTest ()
-  : ns3::Test ("Histogram")
+HistogramTestCase::HistogramTestCase ()
+  : ns3::TestCase ("Histogram")
 {}
 
 
 bool 
-HistogramTest::RunTests (void)
+HistogramTestCase::DoRun (void)
 {
-  bool result = true;
-
   Histogram h0(3.5);
   // Testing floating-point bin widths
   {
-    for (int i=1; i<= 10; i++) h0.AddValue(3.4);
-    for (int i=1; i<= 5; i++) h0.AddValue(3.6);
-
-    NS_TEST_ASSERT_EQUAL (h0.GetBinWidth (0),  3.5);
-    NS_TEST_ASSERT_EQUAL (h0.GetNBins (),  2);
-    NS_TEST_ASSERT_EQUAL (h0.GetBinStart(1),  3.5);
-    NS_TEST_ASSERT_EQUAL (h0.GetBinCount(0),  10);
-    NS_TEST_ASSERT_EQUAL (h0.GetBinCount(1),  5);
+    for (int i=1; i <= 10; i++)
+      { 
+        h0.AddValue (3.4);
+      }
+    
+    for (int i=1; i <= 5; i++)
+      {    
+        h0.AddValue (3.6);
+      }
+    
+    NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinWidth (0),  3.5, 1e-6, "");
+    NS_TEST_EXPECT_MSG_EQ (h0.GetNBins (),  2, "");
+    NS_TEST_EXPECT_MSG_EQ_TOL (h0.GetBinStart (1),  3.5, 1e-6, "");
+    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (0),  10, "");
+    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (1),  5, "");
   }
   
   {
-  // Testing bin expansion
-    h0.AddValue(74.3);
-
-    NS_TEST_ASSERT_EQUAL (h0.GetNBins (),  22);
-
-    /*for (uint32_t i=0; i < h0.GetSize () ; i++)
-    {
-      std::cout << i << ") BinStart:" << h0.GetBinStart (i) << " BinEnd:" << ((double) h0.GetBinStart (i) + h0.GetBinWidth (i)) << " BinCount: " << h0.GetBinCount (i) << std::endl;
-    }*/
-    
-    NS_TEST_ASSERT_EQUAL (h0.GetBinCount (21),  1);
+    // Testing bin expansion
+    h0.AddValue (74.3);
+    NS_TEST_EXPECT_MSG_EQ (h0.GetNBins (), 22, "");
+    NS_TEST_EXPECT_MSG_EQ (h0.GetBinCount (21), 1, "");
   }
  
-  return result;
+  return false;
 }
 
-static HistogramTest gHistogramTest;
+static class HistogramTestSuite : public TestSuite
+{
+public:
+  HistogramTestSuite ()
+    : TestSuite ("histogram", UNIT) 
+  {
+    AddTestCase (new HistogramTestCase ());
+  }
+} g_HistogramTestSuite;
 
-}; // namespace
+} // namespace
 
 
-#endif /* RUN_SELF_TESTS */
-
--- a/src/contrib/net-anim/animation-interface.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/contrib/net-anim/animation-interface.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -141,7 +141,7 @@
     }
   
   // Connect the callback for packet tx events
-  Config::Connect ("/NodeList/*/DeviceList/*/TxRxPointToPoint",
+  Config::Connect ("/ChannelList/*/TxRxPointToPoint",
                    MakeCallback (&AnimationInterface::DevTxTrace, this));
 }
 
--- a/src/core/config.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/config.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -767,7 +767,6 @@
 
 private:
   virtual bool DoRun (void);
-  virtual void DoTeardown (void);
 };
 
 RootNamespaceConfigTestCase::RootNamespaceConfigTestCase ()
@@ -775,17 +774,6 @@
 {
 }
 
-void
-RootNamespaceConfigTestCase::DoTeardown (void)
-{
-  //
-  // The Config system is intertwined with the Names system.  In the process
-  // of parsing the paths in the tests, we create a NamesPriv singleton.  In
-  // order to get a valgrind-clean run we need to clean up that singleton.
-  //
-  Names::Delete ();
-}
-
 bool
 RootNamespaceConfigTestCase::DoRun (void)
 {
@@ -839,7 +827,6 @@
 
 private:
   virtual bool DoRun (void);
-  virtual void DoTeardown (void);
 };
 
 UnderRootNamespaceConfigTestCase::UnderRootNamespaceConfigTestCase ()
@@ -847,17 +834,6 @@
 {
 }
 
-void
-UnderRootNamespaceConfigTestCase::DoTeardown (void)
-{
-  //
-  // The Config system is intertwined with the Names system.  In the process
-  // of parsing the paths in the tests, we create a NamesPriv singleton.  In
-  // order to get a valgrind-clean run we need to clean up that singleton.
-  //
-  Names::Delete ();
-}
-
 bool
 UnderRootNamespaceConfigTestCase::DoRun (void)
 {
@@ -951,7 +927,6 @@
 
 private:
   virtual bool DoRun (void);
-  virtual void DoTeardown (void);
 };
 
 ObjectVectorConfigTestCase::ObjectVectorConfigTestCase ()
@@ -959,17 +934,6 @@
 {
 }
 
-void
-ObjectVectorConfigTestCase::DoTeardown (void)
-{
-  //
-  // The Config system is intertwined with the Names system.  In the process
-  // of parsing the paths in the tests, we create a NamesPriv singleton.  In
-  // order to get a valgrind-clean run we need to clean up that singleton.
-  //
-  Names::Delete ();
-}
-
 bool
 ObjectVectorConfigTestCase::DoRun (void)
 {
@@ -1122,7 +1086,6 @@
 
 private:
   virtual bool DoRun (void);
-  virtual void DoTeardown (void);
 
   int16_t m_newValue;
   std::string m_path;
@@ -1133,17 +1096,6 @@
 {
 }
 
-void
-ObjectVectorTraceConfigTestCase::DoTeardown (void)
-{
-  //
-  // The Config system is intertwined with the Names system.  In the process
-  // of parsing the paths in the tests, we create a NamesPriv singleton.  In
-  // order to get a valgrind-clean run we need to clean up that singleton.
-  //
-  Names::Delete ();
-}
-
 bool
 ObjectVectorTraceConfigTestCase::DoRun (void)
 {
--- a/src/core/names-test-suite.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/names-test-suite.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -86,7 +86,7 @@
 void
 BasicAddTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -154,7 +154,7 @@
 void
 StringContextAddTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -219,7 +219,7 @@
 void
 FullyQualifiedAddTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -287,7 +287,7 @@
 void
 RelativeAddTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -354,7 +354,7 @@
 void
 BasicRenameTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -416,7 +416,7 @@
 void
 StringContextRenameTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -478,7 +478,7 @@
 void
 FullyQualifiedRenameTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -540,7 +540,7 @@
 void
 RelativeRenameTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -602,7 +602,7 @@
 void
 FindPathTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -658,7 +658,7 @@
 void
 BasicFindTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -722,7 +722,7 @@
 void
 StringContextFindTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -786,7 +786,7 @@
 void
 FullyQualifiedFindTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -850,7 +850,7 @@
 void
 RelativeFindTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
@@ -912,7 +912,7 @@
 void
 AlternateFindTestCase::DoTeardown (void)
 {
-  Names::Delete ();
+  Names::Clear ();
 }
 
 bool
--- a/src/core/names.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/names.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -22,7 +22,6 @@
 #include "assert.h"
 #include "abort.h"
 #include "names.h"
-#include "ns3/simulator.h"
 
 namespace ns3 {
 
@@ -94,14 +93,15 @@
   std::string FindName (Ptr<Object> object);
   std::string FindPath (Ptr<Object> object);
 
+  void Clear (void);
+
   Ptr<Object> Find (std::string name);
   Ptr<Object> Find (std::string path, std::string name);
   Ptr<Object> Find (Ptr<Object> context, std::string name);
 
+private:
+  friend class Names;
   static NamesPriv *Get (void);
-  static void Delete (void);
-private:
-  static NamesPriv **DoGet (bool doCreate);
 
   NameNode *IsNamed (Ptr<Object>);
   bool IsDuplicateName (NameNode *node, std::string name);
@@ -113,31 +113,8 @@
 NamesPriv *
 NamesPriv::Get (void)
 {
-  return *(DoGet (true));
-}
-
-NamesPriv **
-NamesPriv::DoGet (bool doCreate)
-{
-  static NamesPriv *ptr = 0;
-
-  if (ptr == 0 && doCreate)
-    {
-      ptr = new NamesPriv;
-      Simulator::ScheduleDestroy (&NamesPriv::Delete);
-    }
-
-  return &ptr;
-}
-
-void 
-NamesPriv::Delete (void)
-{
-  NS_LOG_FUNCTION_NOARGS ();
-
-  NamesPriv **ptr = DoGet (false);
-  delete *ptr;
-  *ptr = 0;
+  static NamesPriv namesPriv;
+  return &namesPriv;
 }
 
 NamesPriv::NamesPriv ()
@@ -152,7 +129,13 @@
 NamesPriv::~NamesPriv ()
 {
   NS_LOG_FUNCTION_NOARGS ();
+  Clear ();
+  m_root.m_name = "";
+}
 
+void
+NamesPriv::Clear (void)
+{
   //
   // Every name is associated with an object in the object map, so freeing the
   // NameNodes in this map will free all of the memory allocated for the NameNodes
@@ -163,9 +146,12 @@
       i->second = 0;
     }
 
+  m_objectMap.clear ();
+
   m_root.m_parent = 0;
-  m_root.m_name = "";
+  m_root.m_name = "Names";
   m_root.m_object = 0;
+  m_root.m_nameMap.clear ();
 }
 
 bool
@@ -618,12 +604,6 @@
 }
 
 void
-Names::Delete (void)
-{
-  NamesPriv::Delete ();
-}
-
-void
 Names::Add (std::string name, Ptr<Object> object)
 {
   bool result = NamesPriv::Get ()->Add (name, object);
@@ -678,6 +658,12 @@
   return NamesPriv::Get ()->FindPath (object);
 }
 
+void
+Names::Clear (void)
+{
+  return NamesPriv::Get ()->Clear ();
+}
+
 Ptr<Object>
 Names::FindInternal (std::string name)
 {
--- a/src/core/names.h	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/names.h	Wed Sep 30 20:15:49 2009 +0400
@@ -278,6 +278,12 @@
   static std::string FindPath (Ptr<Object> object);
 
   /**
+   * Clear the list of objects associated with names.
+   */
+
+  static void Clear (void);
+
+  /**
    * Given a name path string, look to see if there's an object in the system
    * with that associated to it.  If there is, do a GetObject on the resulting
    * object to convert it to the requested typename and return it.
@@ -358,13 +364,6 @@
   template <typename T>
   static Ptr<T> Find (Ptr<Object> context, std::string name);
 
-  /**
-   * Clean up all of the data structures of the implementation and delete the
-   * underlying singleton.  Used to get valgrind-clean runs if the simulator
-   * is not run.  Normally singleton cleanup is scheduled on Simulator::Destroy.
-   */
-  static void Delete (void);
-
 private:
   /**
    * \internal
--- a/src/core/object.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/object.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -18,7 +18,9 @@
  * Authors: Gustavo Carneiro <gjcarneiro@gmail.com>,
  *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
+#include "test.h"
 #include "object.h"
+#include "object-factory.h"
 #include "assert.h"
 #include "singleton.h"
 #include "attribute.h"
@@ -266,15 +268,8 @@
     current = next;
   } while (current != end);
 }
-
 } // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
-
-#include "test.h"
-#include "object-factory.h"
-
 namespace {
 
 class BaseA : public ns3::Object
@@ -350,87 +345,338 @@
 
 namespace ns3 {
 
-class ObjectTest : public Test
+// ===========================================================================
+// Test case to make sure that we can make Objects using CreateObject.
+// ===========================================================================
+class CreateObjectTestCase : public TestCase
 {
 public:
-  ObjectTest ();
-  virtual bool RunTests (void);
+  CreateObjectTestCase ();
+  virtual ~CreateObjectTestCase ();
+
+private:
+  virtual bool DoRun (void);
 };
 
-ObjectTest::ObjectTest ()
-  : Test ("Object")
-{}
+CreateObjectTestCase::CreateObjectTestCase ()
+  : TestCase ("Check CreateObject<Type> template function")
+{
+}
 
-bool 
-ObjectTest::RunTests (void)
+CreateObjectTestCase::~CreateObjectTestCase ()
 {
-  bool result = true;
+}
 
+bool
+CreateObjectTestCase::DoRun (void)
+{
   Ptr<BaseA> baseA = CreateObject<BaseA> ();
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (), baseA);
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0);
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedA> (), 0);
-  baseA = CreateObject<DerivedA> ();
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (), baseA);
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA);
-  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<DerivedA> (), 0);
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>");
+
+  //
+  // Since baseA is a BaseA, we must be able to successfully ask for a BaseA.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA, "GetObject() of same type returns different Ptr");
 
-  baseA = CreateObject<BaseA> ();
-  Ptr<BaseB> baseB = CreateObject<BaseB> ();
-  Ptr<BaseB> baseBCopy = baseB;
-  baseA->AggregateObject (baseB);
-  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseA> (), 0);
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseB> (), 0);
-  NS_TEST_ASSERT_EQUAL (baseA->GetObject<DerivedB> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseB> (), 0);
-  NS_TEST_ASSERT_EQUAL (baseB->GetObject<DerivedB> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseA> (), 0);
-  NS_TEST_ASSERT_EQUAL (baseB->GetObject<DerivedA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<BaseA> (), 0);
+  //
+  // Since BaseA is a BaseA and not a DerivedA, we must not find a DerivedA if we look.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0, "GetObject() of unrelated type returns nonzero pointer");
+
+  //
+  // Since baseA is not a BaseA, we must not be able to ask for a DerivedA even if we
+  // try an implied cast back to a BaseA.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0, "GetObject() of unrelated returns nonzero Ptr");
 
   baseA = CreateObject<DerivedA> ();
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<DerivedA> with implicit cast to BaseA");
+
+  //
+  // If we create a DerivedA and cast it to a BaseA, then if we do a GetObject for
+  // that BaseA we should get the same address (same Object).
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA, "Unable to GetObject<BaseA> on BaseA");
+
+  //
+  // Since we created a DerivedA and cast it to a BaseA, we should be able to 
+  // get back a DerivedA and it should be the original Ptr.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA, "GetObject() of the original type returns different Ptr");
+
+  // If we created a DerivedA and cast it to a BaseA, then we GetObject for the 
+  // same DerivedA and cast it back to the same BaseA, we should get the same 
+  // object.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA, "GetObject returns different Ptr");
+
+  return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test case to make sure that we can aggregate Objects.
+// ===========================================================================
+class AggregateObjectTestCase : public TestCase
+{
+public:
+  AggregateObjectTestCase ();
+  virtual ~AggregateObjectTestCase ();
+
+private:
+  virtual bool DoRun (void);
+};
+
+AggregateObjectTestCase::AggregateObjectTestCase ()
+  : TestCase ("Check Object aggregation functionality")
+{
+}
+
+AggregateObjectTestCase::~AggregateObjectTestCase ()
+{
+}
+
+bool
+AggregateObjectTestCase::DoRun (void)
+{
+  Ptr<BaseA> baseA = CreateObject<BaseA> ();
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>");
+
+  Ptr<BaseB> baseB = CreateObject<BaseB> ();
+  NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<BaseB>");
+
+  Ptr<BaseB> baseBCopy = baseB;
+  NS_TEST_ASSERT_MSG_NE (baseBCopy, 0, "Unable to copy BaseB");
+
+  //
+  // Make an aggregation of a BaseA object and a BaseB object.
+  //
+  baseA->AggregateObject (baseB);
+
+  //
+  // We should be able to ask the aggregation (through baseA) for the BaseA part
+  // of the aggregation.
+  //
+  NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0, "Cannot GetObject (through baseA) for BaseA Object");
+
+  //
+  // There is no DerivedA in this picture, so we should not be able to GetObject
+  // for that type.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0, "Unexpectedly found a DerivedA through baseA");
+
+  //
+  // We should be able to ask the aggregation (through baseA) for the BaseB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0, "Cannot GetObject (through baseA) for BaseB Object");
+
+  //
+  // There is no DerivedB in this picture, so we should not be able to GetObject
+  // for that type.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0, "Unexpectedly found a DerivedB through baseA");
+
+  //
+  // We should be able to ask the aggregation (through baseA) for the BaseB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0, "Cannot GetObject (through baseB) for BaseB Object");
+
+  //
+  // There is no DerivedB in this picture, so we should not be able to GetObject
+  // for that type.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0, "Unexpectedly found a DerivedB through baseB");
+
+  //
+  // We should be able to ask the aggregation (through baseB) for the BaseA part
+  // of the aggregation.
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0, "Cannot GetObject (through baseB) for BaseA Object");
+
+  //
+  // There is no DerivedA in this picture, so we should not be able to GetObject
+  // for that type.
+  //
+  NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0, "Unexpectedly found a DerivedA through baseB");
+
+  //
+  // baseBCopy is a copy of the original Ptr to the Object BaseB.  Even though
+  // we didn't use baseBCopy directly in the aggregations, the object to which
+  // it points was used, therefore, we should be able to use baseBCopy as if
+  // it were baseB and get a BaseA out of the aggregation.
+  //
+  NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object");
+
+  //
+  // Now, change the underlying type of the objects to be the derived types.
+  //
+  baseA = CreateObject<DerivedA> ();
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<DerivedA> with implicit cast to BaseA");
+
   baseB = CreateObject<DerivedB> ();
+  NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<DerivedB> with implicit cast to BaseB");
+
+  //
+  // Create an aggregation of two objects, both of the derived types; and leave
+  // an unaggregated copy of one lying around.
+  //
   baseBCopy = baseB;
   baseA->AggregateObject (baseB);
-  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<DerivedB> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseA->GetObject<BaseB> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<DerivedA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<DerivedA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseBCopy->GetObject<BaseA> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<DerivedB> (), 0);
-  NS_TEST_ASSERT_UNEQUAL (baseB->GetObject<BaseB> (), 0);
+
+  //
+  // We should be able to ask the aggregation (through baseA) for the DerivedB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0, "Cannot GetObject (through baseA) for DerivedB Object");
+
+  //
+  // Since the DerivedB is also a BaseB, we should be able to ask the aggregation 
+  // (through baseA) for the BaseB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0, "Cannot GetObject (through baseA) for BaseB Object");
+
+  //
+  // We should be able to ask the aggregation (through baseB) for the DerivedA part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0, "Cannot GetObject (through baseB) for DerivedA Object");
+
+  //
+  // Since the DerivedA is also a BaseA, we should be able to ask the aggregation 
+  // (through baseB) for the BaseA part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0, "Cannot GetObject (through baseB) for BaseA Object");
 
+  //
+  // baseBCopy is a copy of the original Ptr to the Object BaseB.  Even though
+  // we didn't use baseBCopy directly in the aggregations, the object to which
+  // it points was used, therefore, we should be able to use baseBCopy as if
+  // it were baseB (same underlying Object) and get a BaseA and a DerivedA out 
+  // of the aggregation through baseBCopy.
+  //
+  NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object");
+  NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0, "Cannot GetObject (through baseBCopy) for a BaseA Object");
+
+  //
+  // Since the Ptr<BaseB> is actually a DerivedB, we should be able to ask the 
+  // aggregation (through baseB) for the DerivedB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0, "Cannot GetObject (through baseB) for DerivedB Object");
+
+  //
+  // Since the DerivedB was cast to a BaseB, we should be able to ask the 
+  // aggregation (through baseB) for the BaseB part
+  //
+  NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0, "Cannot GetObject (through baseB) for BaseB Object");
+
+  //
+  // Make sure reference counting works in the aggregate.  Create two Objects
+  // and aggregate them, then release one of them.  The aggregation should
+  // keep a reference to both and the Object we released should still be there.
+  //
   baseA = CreateObject<BaseA> ();
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to CreateObject<BaseA>");
+
   baseB = CreateObject<BaseB> ();
+  NS_TEST_ASSERT_MSG_NE (baseB, 0, "Unable to CreateObject<BaseA>");
+
   baseA->AggregateObject (baseB);
   baseA = 0;
+
   baseA = baseB->GetObject<BaseA> ();
+  NS_TEST_ASSERT_MSG_NE (baseA, 0, "Unable to GetObject on released object");
 
+  return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test case to make sure that an Object factory can create Objects
+// ===========================================================================
+class ObjectFactoryTestCase : public TestCase
+{
+public:
+  ObjectFactoryTestCase ();
+  virtual ~ObjectFactoryTestCase ();
 
-  // Test the object creation code of TypeId
+private:
+  virtual bool DoRun (void);
+};
+
+ObjectFactoryTestCase::ObjectFactoryTestCase ()
+  : TestCase ("Check ObjectFactory functionality")
+{
+}
+
+ObjectFactoryTestCase::~ObjectFactoryTestCase ()
+{
+}
+
+bool
+ObjectFactoryTestCase::DoRun (void)
+{
   ObjectFactory factory;
+
+  //
+  // Create an Object of type BaseA through an object factory.
+  //
   factory.SetTypeId (BaseA::GetTypeId ());
   Ptr<Object> a = factory.Create ();
-  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (), a);
-  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (DerivedA::GetTypeId ()), 0);
-  NS_TEST_ASSERT_EQUAL (a->GetObject<DerivedA> (), 0);
+  NS_TEST_ASSERT_MSG_NE (a, 0, "Unable to factory.Create() a BaseA");
+
+  //
+  // What we made should be a BaseA, not have anything to do with a DerivedA
+  //
+  NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (DerivedA::GetTypeId ()), 0, "BaseA is unexpectedly a DerivedA also");
+
+  //
+  // The BaseA we got should not respond to a GetObject for DerivedA
+  //
+  NS_TEST_ASSERT_MSG_EQ (a->GetObject<DerivedA> (), 0, "BaseA unexpectedly responds to GetObject for DerivedA");
+
+  //
+  // Now tell the factory to make DerivedA Objects and create one with an 
+  // implied cast back to a BaseA
+  //
   factory.SetTypeId (DerivedA::GetTypeId ());
   a = factory.Create ();
-  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (), a);
-  NS_TEST_ASSERT_EQUAL (a->GetObject<BaseA> (DerivedA::GetTypeId ()), a);
-  NS_TEST_ASSERT_UNEQUAL (a->GetObject<DerivedA> (), 0);
+
+  //
+  // Since the DerivedA has a BaseA part, we should be able to use GetObject to 
+  // dynamically cast back to a BaseA.
+  //
+  NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (), a, "Unable to use GetObject as dynamic_cast<BaseA>()");
 
+  //
+  // Since a is already a BaseA and is really a DerivedA, we should be able to
+  // GetObject for the DerivedA and cast it back to a BaseA getting the same
+  // value that is there.
+  //
+  NS_TEST_ASSERT_MSG_EQ (a->GetObject<BaseA> (DerivedA::GetTypeId ()), a, "GetObject with implied cast returns different Ptr");
 
-  return result;
+  //
+  // Since a declared a BaseA, even if it is really a DerivedA, we should not
+  // be able to GetOBject for a DerivedA since this would break the type
+  // declaration.
+  //
+  NS_TEST_ASSERT_MSG_NE (a->GetObject<DerivedA> (), 0, "Unexpectedly able to work around C++ type system");
+
+  return GetErrorStatus ();
 }
 
-static ObjectTest g_interfaceObjectTests;
+// ===========================================================================
+// The Test Suite that glues the Test Cases together.
+// ===========================================================================
+class ObjectTestSuite : public TestSuite
+{
+public:
+  ObjectTestSuite ();
+};
 
+ObjectTestSuite::ObjectTestSuite ()
+  : TestSuite ("object", BVT)
+{
+  AddTestCase (new CreateObjectTestCase);
+  AddTestCase (new AggregateObjectTestCase);
+  AddTestCase (new ObjectFactoryTestCase);
+}
+
+ObjectTestSuite objectTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
-
-
--- a/src/core/random-variable.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/random-variable.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -30,8 +30,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>       
 #include <sstream>
+#include <vector>
 
-
+#include "test.h"
 #include "assert.h"
 #include "config.h"
 #include "integer.h"
@@ -1710,96 +1711,118 @@
   return is;
 }
 
-
-
-}//namespace ns3
-
- 
-
-#ifdef RUN_SELF_TESTS
-#include "test.h"
-#include <vector>
-
-namespace ns3 {
-
-
-class RandomVariableTest : public Test
+class BasicRandomNumberTestCase : public TestCase
 {
 public:
-  RandomVariableTest () : Test ("RandomVariable") {}
-  virtual bool RunTests (void)
-  {
-    bool result = true;
-    const double desired_mean = 1.0;
-    const double desired_stddev = 1.0;
-    double tmp = log (1 + (desired_stddev/desired_mean)*(desired_stddev/desired_mean));
-    double sigma = sqrt (tmp);
-    double mu = log (desired_mean) - 0.5*tmp;
-
-    // Test a custom lognormal instance
-    {
-      LogNormalVariable lognormal (mu, sigma);
-      vector<double> samples;
-      const int NSAMPLES = 10000;
-      double sum = 0;
-      for (int n = NSAMPLES; n; --n)
-        {
-          double value = lognormal.GetValue ();
-          sum += value;
-          samples.push_back (value);
-        }
-      double obtained_mean = sum / NSAMPLES;
-      sum = 0;
-      for (vector<double>::iterator iter = samples.begin (); iter != samples.end (); iter++)
-        {
-          double tmp = (*iter - obtained_mean);
-          sum += tmp*tmp;
-        }
-      double obtained_stddev = sqrt (sum / (NSAMPLES - 1));
+  BasicRandomNumberTestCase ();
+  virtual ~BasicRandomNumberTestCase () {}
 
-      if (not (obtained_mean/desired_mean > 0.90 and obtained_mean/desired_mean < 1.10))
-        {
-          result = false;
-          Failure () << "Obtained lognormal mean value " << obtained_mean << ", expected " << desired_mean << std::endl;
-        }
-
-      if (not (obtained_stddev/desired_stddev > 0.90 and obtained_stddev/desired_stddev < 1.10))
-        {
-          result = false;
-          Failure () << "Obtained lognormal stddev value " << obtained_stddev <<
-            ", expected " << desired_stddev << std::endl;
-        }
-    }
-
-    // Test attribute serialization
-    {
-      {
-        RandomVariableValue val;
-        val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ());
-        RandomVariable rng = val.Get ();
-        NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2");
-      }
-      {
-        RandomVariableValue val;
-        val.DeserializeFromString ("Normal:0.1:0.2", MakeRandomVariableChecker ());
-        RandomVariable rng = val.Get ();
-        NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2");
-      }
-      {
-        RandomVariableValue val;
-        val.DeserializeFromString ("Normal:0.1:0.2:0.15", MakeRandomVariableChecker ());
-        RandomVariable rng = val.Get ();
-        NS_TEST_ASSERT_EQUAL (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2:0.15");
-      }
-    }
-
-    return result;
-  }
+private:
+  virtual bool DoRun (void);
 };
 
+BasicRandomNumberTestCase::BasicRandomNumberTestCase ()
+  : TestCase ("Check basic random number operation")
+{
+}
 
-static RandomVariableTest g_random_variable_tests;
+bool
+BasicRandomNumberTestCase::DoRun (void)
+{
+  const double desiredMean = 1.0;
+  const double desiredStdDev = 1.0;
+
+  double tmp = log (1 + (desiredStdDev / desiredMean) * (desiredStdDev / desiredMean));
+  double sigma = sqrt (tmp);
+  double mu = log (desiredMean) - 0.5 * tmp;
+
+  //
+  // Test a custom lognormal instance to see if its moments have any relation
+  // expected reality.
+  //
+  LogNormalVariable lognormal (mu, sigma);
+  vector<double> samples;
+  const int NSAMPLES = 10000;
+  double sum = 0;
+  
+  //
+  // Get and store a bunch of samples.  As we go along sum them and then find
+  // the mean value of the samples.
+  //
+  for (int n = NSAMPLES; n; --n)
+    {
+      double value = lognormal.GetValue ();
+      sum += value;
+      samples.push_back (value);
+    }
+  double obtainedMean = sum / NSAMPLES;
+  NS_TEST_EXPECT_MSG_EQ_TOL (obtainedMean, desiredMean, 0.1, "Got unexpected mean value from LogNormalVariable");
+  
+  //
+  // Wander back through the saved stamples and find their standard deviation
+  //
+  sum = 0;
+  for (vector<double>::iterator iter = samples.begin (); iter != samples.end (); iter++)
+    {
+      double tmp = (*iter - obtainedMean);
+      sum += tmp * tmp;
+    }
+  double obtainedStdDev = sqrt (sum / (NSAMPLES - 1));
+  NS_TEST_EXPECT_MSG_EQ_TOL (obtainedStdDev, desiredStdDev, 0.1, "Got unexpected standard deviation from LogNormalVariable");
+
+  return GetErrorStatus ();
+}
+
+class RandomNumberSerializationTestCase : public TestCase
+{
+public:
+  RandomNumberSerializationTestCase ();
+  virtual ~RandomNumberSerializationTestCase () {}
+
+private:
+  virtual bool DoRun (void);
+};
+
+RandomNumberSerializationTestCase::RandomNumberSerializationTestCase ()
+  : TestCase ("Check basic random number operation")
+{
+}
+
+bool
+RandomNumberSerializationTestCase::DoRun (void)
+{
+  RandomVariableValue val;
+  val.DeserializeFromString ("Uniform:0.1:0.2", MakeRandomVariableChecker ());
+  RandomVariable rng = val.Get ();
+  NS_TEST_ASSERT_MSG_EQ (val.SerializeToString (MakeRandomVariableChecker ()), "Uniform:0.1:0.2", 
+                         "Deserialize and Serialize \"Uniform:0.1:0.2\" mismatch");
+
+  val.DeserializeFromString ("Normal:0.1:0.2", MakeRandomVariableChecker ());
+  rng = val.Get ();
+  NS_TEST_ASSERT_MSG_EQ (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2",
+                         "Deserialize and Serialize \"Normal:0.1:0.2\" mismatch");
+
+  val.DeserializeFromString ("Normal:0.1:0.2:0.15", MakeRandomVariableChecker ());
+  rng = val.Get ();
+  NS_TEST_ASSERT_MSG_EQ (val.SerializeToString (MakeRandomVariableChecker ()), "Normal:0.1:0.2:0.15",
+                         "Deserialize and Serialize \"Normal:0.1:0.2:0.15\" mismatch");
+
+  return GetErrorStatus ();
+}
+
+class BasicRandomNumberTestSuite : public TestSuite
+{
+public:
+  BasicRandomNumberTestSuite ();
+};
+
+BasicRandomNumberTestSuite::BasicRandomNumberTestSuite ()
+  : TestSuite ("basic-random-number", BVT)
+{
+  AddTestCase (new BasicRandomNumberTestCase);
+  AddTestCase (new RandomNumberSerializationTestCase);
+}
+
+BasicRandomNumberTestSuite BasicRandomNumberTestSuite;
 
 }//namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/core/test.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/test.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -124,7 +124,8 @@
 {
   DoReportStart ();
   DoSetup ();
-  m_error |= DoRun ();
+  bool status = DoRun ();
+  m_error |= status;
   DoTeardown ();
   if (m_error == false)
     {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/traced-callback-test-suite.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -0,0 +1,125 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "test.h"
+#include "traced-callback.h"
+
+using namespace ns3;
+
+class BasicTracedCallbackTestCase : public TestCase
+{
+public:
+  BasicTracedCallbackTestCase ();
+  virtual ~BasicTracedCallbackTestCase () {}
+
+private:
+  virtual bool DoRun (void);
+
+  void CbOne (uint8_t a, double b);
+  void CbTwo (uint8_t a, double b);
+
+  bool m_one;
+  bool m_two;
+};
+
+BasicTracedCallbackTestCase::BasicTracedCallbackTestCase ()
+  : TestCase ("Check basic TracedCallback operation")
+{
+}
+
+void
+BasicTracedCallbackTestCase::CbOne (uint8_t a, double b)
+{
+  m_one = true;
+}
+
+void
+BasicTracedCallbackTestCase::CbTwo (uint8_t a, double b)
+{
+  m_two = true;
+}
+
+bool
+BasicTracedCallbackTestCase::DoRun (void)
+{
+  //
+  // Create a traced callback and connect it up to our target methods.  All that
+  // these methods do is to set corresponding member variables m_one and m_two.
+  //
+  TracedCallback<uint8_t, double> trace;
+
+  //
+  // Connect both callbacks to their respective test methods.  If we hit the 
+  // trace, both callbacks should be called and the two variables  should be set
+  // to true.
+  //
+  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+  m_one = false;
+  m_two = false;
+  trace (1, 2);
+  NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+  //
+  // If we now disconnect callback one then only callback two should be called.
+  //
+  trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+  m_one = false;
+  m_two = false;
+  trace (1, 2);
+  NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+  //
+  // If we now disconnect callback two then neither callback should be called.
+  //
+  trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+  m_one = false;
+  m_two = false;
+  trace (1, 2);
+  NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+  NS_TEST_ASSERT_MSG_EQ (m_two, false, "Callback CbTwo unexpectedly called");
+
+  //
+  // If we connect them back up, then both callbacks should be called.
+  //
+  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+  trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+  m_one = false;
+  m_two = false;
+  trace (1, 2);
+  NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+  NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+  return GetErrorStatus ();
+}
+
+class TracedCallbackTestSuite : public TestSuite
+{
+public:
+  TracedCallbackTestSuite ();
+};
+
+TracedCallbackTestSuite::TracedCallbackTestSuite ()
+  : TestSuite ("traced-callback", UNIT)
+{
+  AddTestCase (new BasicTracedCallbackTestCase);
+}
+
+TracedCallbackTestSuite tracedCallbackTestSuite;
--- a/src/core/traced-callback.cc	Wed Sep 30 20:15:41 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "traced-callback.h"
-
-#ifdef RUN_SELF_TESTS
-
-#include "test.h"
-
-namespace ns3 {
-
-class TracedCallbackTest : public Test 
-{
-public:
-  TracedCallbackTest ();
-  virtual ~TracedCallbackTest ();
-  virtual bool RunTests (void);
-private:
-  void CbOne (uint8_t a, double b);
-  void CbTwo (uint8_t a, double b);
-
-  bool m_one;
-  bool m_two;
-};
-
-TracedCallbackTest::TracedCallbackTest ()
-  : Test ("TracedCallback")
-{}
-TracedCallbackTest::~TracedCallbackTest ()
-{}
-void
-TracedCallbackTest::CbOne (uint8_t a, double b)
-{
-  m_one = true;
-}
-void
-TracedCallbackTest::CbTwo (uint8_t a, double b)
-{
-  m_two = true;
-}
-bool 
-TracedCallbackTest::RunTests (void)
-{
-  bool result = true;
-
-  TracedCallback<uint8_t,double> trace;
-  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
-  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
-  m_one = false;
-  m_two = false;
-  trace (1, 2);
-  NS_TEST_ASSERT (m_one);
-  NS_TEST_ASSERT (m_two);
-
-  trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
-  m_one = false;
-  m_two = false;
-  trace (1, 2);
-  NS_TEST_ASSERT (!m_one);
-  NS_TEST_ASSERT (m_two);
-  trace.DisconnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
-  m_one = false;
-  m_two = false;
-  trace (1, 2);
-  NS_TEST_ASSERT (!m_one);
-  NS_TEST_ASSERT (!m_two);
-
-  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbOne, this));
-  trace.ConnectWithoutContext (MakeCallback (&TracedCallbackTest::CbTwo, this));
-  m_one = false;
-  m_two = false;
-  trace (1, 2);
-  NS_TEST_ASSERT (m_one);
-  NS_TEST_ASSERT (m_two);
-
-  return result;
-}
-
-static TracedCallbackTest g_eventTraceTest;
-
-}//namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/core/wscript	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/core/wscript	Wed Sep 30 20:15:49 2009 +0400
@@ -70,7 +70,6 @@
         'object-vector.cc',
         'object-factory.cc',
         'global-value.cc',
-        'traced-callback.cc',
         'trace-source-accessor.cc',
         'config.cc',
         'callback.cc',
@@ -80,6 +79,7 @@
         'callback-test-suite.cc',
         'names-test-suite.cc',
         'type-traits-test-suite.cc',
+        'traced-callback-test-suite.cc',
         ]
 
     headers = bld.new_task_gen('ns3header')
--- a/src/devices/mesh/dot11s/dot11s-mac-header.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/dot11s/dot11s-mac-header.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -22,7 +22,6 @@
 #include "ns3/address-utils.h"
 #include "dot11s-mac-header.h"
 #include "ns3/packet.h"
-#include "ns3/test.h"
 
 namespace ns3 {
 namespace dot11s {
@@ -314,67 +313,6 @@
   m_actionValue = i.ReadU8 ();
   return i.GetDistanceFrom (start);
 }
-#ifdef RUN_SELF_TESTS
 
-/// Built-in self test for Dot11sMacHeader
-struct Dot11sMacHeaderBist : public Test
-{
-  Dot11sMacHeaderBist () :
-    Test ("Mesh/802.11s/MeshHeader")
-  {
-  }
-  virtual bool
-  RunTests ();
-};
-
-/// Test instance
-static Dot11sMacHeaderBist g_Dot11sMacHeaderBist;
-
-bool
-Dot11sMacHeaderBist::RunTests ()
-{
-  bool result (true);
-    {
-      MeshHeader a;
-      a.SetAddressExt (3);
-      a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
-      a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
-      a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
-      a.SetMeshTtl (122);
-      a.SetMeshSeqno (321);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      MeshHeader b;
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-    {
-      MeshHeader a;
-      a.SetAddressExt (2);
-      a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
-      a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
-      a.SetMeshTtl (122);
-      a.SetMeshSeqno (321);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      MeshHeader b;
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-    {
-      MeshHeader a;
-      a.SetAddressExt (1);
-      a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
-      a.SetMeshTtl (122);
-      a.SetMeshSeqno (321);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      MeshHeader b;
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-  return result;
-}
-#endif
 } //namespace dot11s
 } // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/dot11s/dot11s-test-suite.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -0,0 +1,292 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Pavel Boyko <boyko@iitp.ru>
+ */
+#include "ns3/test.h"
+#include "ns3/packet.h"
+#include "ns3/simulator.h"
+#include "dot11s-mac-header.h"
+#include "hwmp-rtable.h"
+#include "peer-link-frame.h"
+#include "ie-dot11s-peer-management.h"
+
+namespace ns3 {
+namespace dot11s {
+
+/// Built-in self test for FlameHeader
+struct MeshHeaderTest : public TestCase
+{
+  MeshHeaderTest () :
+    TestCase ("Dot11sMeshHeader roundtrip serialization")
+  {
+  }
+  bool DoRun ();
+};
+
+bool
+MeshHeaderTest::DoRun ()
+{
+  {
+    MeshHeader a;
+    a.SetAddressExt (3);
+    a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
+    a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
+    a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
+    a.SetMeshTtl (122);
+    a.SetMeshSeqno (321);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    MeshHeader b;
+    packet->RemoveHeader (b);
+    NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 3 addresses");
+  }
+  {
+    MeshHeader a;
+    a.SetAddressExt (2);
+    a.SetAddr5 (Mac48Address ("11:00:33:00:55:00"));
+    a.SetAddr6 (Mac48Address ("00:22:00:44:00:66"));
+    a.SetMeshTtl (122);
+    a.SetMeshSeqno (321);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    MeshHeader b;
+    packet->RemoveHeader (b);
+    NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 2 addresses");
+  }
+  {
+    MeshHeader a;
+    a.SetAddressExt (1);
+    a.SetAddr4 (Mac48Address ("11:22:33:44:55:66"));
+    a.SetMeshTtl (122);
+    a.SetMeshSeqno (321);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    MeshHeader b;
+    packet->RemoveHeader (b);
+    NS_TEST_ASSERT_MSG_EQ (a, b, "Mesh header roundtrip serialization works, 1 address");
+  }
+  return false;
+}
+//-----------------------------------------------------------------------------
+/// Unit test for HwmpRtable
+class HwmpRtableTest : public TestCase
+{
+public:
+  HwmpRtableTest ();
+  virtual bool DoRun ();
+
+private:
+  /// Test Add apth and lookup path;
+  void TestLookup ();
+  /**
+   * \name Test add path and try to lookup after entry has expired
+   * \{
+   */
+  void TestAddPath ();
+  void TestExpire ();
+  ///\}
+  /**
+   * \name Test add precursors and find precursor list in rtable
+   * \{
+   */
+  void TestPrecursorAdd ();
+  void TestPrecursorFind ();
+  ///\}
+private:
+  Mac48Address dst;
+  Mac48Address hop;
+  uint32_t iface;
+  uint32_t metric;
+  uint32_t seqnum;
+  Time expire;
+  Ptr<HwmpRtable> table;
+  std::vector<Mac48Address> precursors;
+};
+
+HwmpRtableTest::HwmpRtableTest () :
+  TestCase ("HWMP routing table"), 
+  dst ("01:00:00:01:00:01"), 
+  hop ("01:00:00:01:00:03"),
+  iface (8010), 
+  metric (10), 
+  seqnum (1), 
+  expire (Seconds (10))
+{
+  precursors.push_back (Mac48Address ("00:10:20:30:40:50"));
+  precursors.push_back (Mac48Address ("00:11:22:33:44:55"));
+  precursors.push_back (Mac48Address ("00:01:02:03:04:05"));
+}
+
+void
+HwmpRtableTest::TestLookup ()
+{
+  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
+
+  // Reactive path
+  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
+  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactive (dst) == correct), true, "Reactive lookup works");
+  table->DeleteReactivePath (dst);
+  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive lookup works");
+
+  // Proactive
+  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
+  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactive () == correct), true, "Proactive lookup works");
+  table->DeleteProactivePath (dst);
+  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive lookup works");
+}
+
+void
+HwmpRtableTest::TestAddPath ()
+{
+  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
+  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
+}
+
+void
+HwmpRtableTest::TestExpire ()
+{
+  // this is assumed to be called when path records are already expired
+  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
+  NS_TEST_EXPECT_MSG_EQ ((table->LookupReactiveExpired (dst) == correct), true, "Reactive expiration works");
+  NS_TEST_EXPECT_MSG_EQ ((table->LookupProactiveExpired () == correct), true, "Proactive expiration works");
+
+  NS_TEST_EXPECT_MSG_EQ (table->LookupReactive (dst).IsValid (), false, "Reactive expiration works");
+  NS_TEST_EXPECT_MSG_EQ (table->LookupProactive ().IsValid (), false, "Proactive expiration works");
+}
+
+void
+HwmpRtableTest::TestPrecursorAdd ()
+{
+  for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != precursors.end (); i++)
+    {
+      table->AddPrecursor (dst, iface, *i);
+      // Check that duplicates are filtered
+      table->AddPrecursor (dst, iface, *i);
+    }
+}
+
+void
+HwmpRtableTest::TestPrecursorFind ()
+{
+  HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst);
+  NS_TEST_EXPECT_MSG_EQ (precursors.size (), precursorList.size (), "Precursors size works");
+  for (unsigned i = 0; i < precursors.size (); i++)
+    {
+      NS_TEST_EXPECT_MSG_EQ (precursorList[i].first, iface, "Precursors lookup works");
+      NS_TEST_EXPECT_MSG_EQ (precursorList[i].second, precursors[i], "Precursors lookup works");
+    }
+}
+
+bool
+HwmpRtableTest::DoRun ()
+{
+  table = CreateObject<HwmpRtable> ();
+
+  Simulator::Schedule (Seconds (0), &HwmpRtableTest::TestLookup, this);
+  Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this);
+  Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this);
+  Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this);
+  Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind, this);
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return GetErrorStatus ();
+}
+//-----------------------------------------------------------------------------
+/// Built-in self test for PeerLinkFrameStart
+struct PeerLinkFrameStartTest : public TestCase
+{
+  PeerLinkFrameStartTest () :
+    TestCase ("PeerLinkFrames (open, confirm, close) unit tests")
+  {
+  }
+  virtual bool DoRun ();
+};
+
+bool
+PeerLinkFrameStartTest::DoRun ()
+{
+  {
+    PeerLinkFrameStart a;
+    PeerLinkFrameStart::PlinkFrameStartFields fields;
+    fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN);
+    fields.capability = 0;
+    fields.aid = 101;
+    fields.reasonCode = 12;
+    fields.meshId = IeMeshId ("qwertyuiop");
+    a.SetPlinkFrameStart (fields);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    PeerLinkFrameStart b;
+    b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN));
+    packet->RemoveHeader (b);
+    NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_OPEN works");
+  }
+  {
+    PeerLinkFrameStart a;
+    PeerLinkFrameStart::PlinkFrameStartFields fields;
+    fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM);
+    fields.capability = 0;
+    fields.aid = 1234;
+    fields.reasonCode = 12;
+    fields.meshId = IeMeshId ("qwerty");
+    a.SetPlinkFrameStart (fields);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    PeerLinkFrameStart b;
+    b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM));
+    packet->RemoveHeader (b);
+    NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CONFIRM works");
+  }
+  {
+    PeerLinkFrameStart a;
+    PeerLinkFrameStart::PlinkFrameStartFields fields;
+    fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE);
+    fields.capability = 0;
+    fields.aid = 10;
+    fields.meshId = IeMeshId ("qqq");
+    fields.reasonCode = 12;
+    a.SetPlinkFrameStart (fields);
+    Ptr<Packet> packet = Create<Packet> ();
+    packet->AddHeader (a);
+    PeerLinkFrameStart b;
+    b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE));
+    packet->RemoveHeader (b);
+    NS_TEST_EXPECT_MSG_EQ (a, b, "PEER_LINK_CLOSE works");
+  }
+  return GetErrorStatus ();
+}
+//-----------------------------------------------------------------------------
+class Dot11sTestSuite : public TestSuite
+{
+public:
+  Dot11sTestSuite ();
+};
+
+Dot11sTestSuite::Dot11sTestSuite ()
+  : TestSuite ("devices-mesh-dot11s", UNIT)
+{
+  AddTestCase (new MeshHeaderTest);
+  AddTestCase (new HwmpRtableTest);
+  AddTestCase (new PeerLinkFrameStartTest);
+}
+
+Dot11sTestSuite g_dot11sTestSuite;
+}
+}
--- a/src/devices/mesh/dot11s/hwmp-rtable.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/dot11s/hwmp-rtable.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -263,131 +263,5 @@
   return !(retransmitter == Mac48Address::GetBroadcast () && ifIndex == INTERFACE_ANY && metric == MAX_METRIC
       && seqnum == 0);
 }
-#ifdef RUN_SELF_TESTS
-/// Unit test for HwmpRtable
-class HwmpRtableTest : public Test
-{
-public:
-  HwmpRtableTest ();
-  virtual bool
-  RunTests ();
-
-private:
-  /// Test Add apth and lookup path;
-  void
-  TestLookup ();
-  /**
-   * \name Test add path and try to lookup after entry has expired
-   * \{
-   */
-  void
-  TestAddPath ();
-  void
-  TestExpire ();
-  ///\}
-  /**
-   * \name Test add precursors and find precursor list in rtable
-   * \{
-   */
-  void
-  TestPrecursorAdd ();
-  void
-  TestPrecursorFind ();
-  ///\}
-private:
-  bool result;
-
-  Mac48Address dst;
-  Mac48Address hop;
-  uint32_t iface;
-  uint32_t metric;
-  uint32_t seqnum;
-  Time expire;
-  Ptr<HwmpRtable> table;
-  std::vector<Mac48Address> precursors;
-};
-/// Test instance
-static HwmpRtableTest g_HwmpRtableTest;
-
-HwmpRtableTest::HwmpRtableTest () :
-  Test ("Mesh/802.11s/HwmpRtable"), result (true), dst ("01:00:00:01:00:01"), hop ("01:00:00:01:00:03"),
-      iface (8010), metric (10), seqnum (1), expire (Seconds (10))
-{
-  precursors.push_back (Mac48Address ("00:10:20:30:40:50"));
-  precursors.push_back (Mac48Address ("00:11:22:33:44:55"));
-  precursors.push_back (Mac48Address ("00:01:02:03:04:05"));
-}
-void
-HwmpRtableTest::TestLookup ()
-{
-  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
-
-  // Reactive path
-  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
-  NS_TEST_ASSERT (table->LookupReactive (dst) == correct);
-  table->DeleteReactivePath (dst);
-  NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ());
-
-  // Proactive
-  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
-  NS_TEST_ASSERT (table->LookupProactive () == correct);
-  table->DeleteProactivePath (dst);
-  NS_TEST_ASSERT (!table->LookupProactive ().IsValid ());
-}
-void
-HwmpRtableTest::TestAddPath ()
-{
-  table->AddReactivePath (dst, hop, iface, metric, expire, seqnum);
-  table->AddProactivePath (metric, dst, hop, iface, expire, seqnum);
-}
-void
-HwmpRtableTest::TestExpire ()
-{
-  // this is assumed to be called when path records are already expired
-  HwmpRtable::LookupResult correct (hop, iface, metric, seqnum);
-  NS_TEST_ASSERT (table->LookupReactiveExpired (dst) == correct);
-  NS_TEST_ASSERT (table->LookupProactiveExpired () == correct);
-
-  NS_TEST_ASSERT (!table->LookupReactive (dst).IsValid ());
-  NS_TEST_ASSERT (!table->LookupProactive ().IsValid ());
-}
-void
-HwmpRtableTest::TestPrecursorAdd ()
-{
-  for (std::vector<Mac48Address>::const_iterator i = precursors.begin (); i != precursors.end (); i++)
-    {
-      table->AddPrecursor (dst, iface, *i);
-      // Check that duplicates are filtered
-      table->AddPrecursor (dst, iface, *i);
-    }
-}
-void
-HwmpRtableTest::TestPrecursorFind ()
-{
-  HwmpRtable::PrecursorList precursorList = table->GetPrecursors (dst);
-  NS_TEST_ASSERT (precursors.size () == precursorList.size ());
-  for (unsigned int i = 0; i < precursors.size (); i++)
-    {
-      NS_TEST_ASSERT (precursorList[i].first == iface);
-      NS_TEST_ASSERT (precursorList[i].second == precursors[i]);
-    }
-}
-bool
-HwmpRtableTest::RunTests ()
-{
-  table = CreateObject<HwmpRtable> ();
-
-  Simulator::Schedule (Seconds (0), &HwmpRtableTest::TestLookup, this);
-  Simulator::Schedule (Seconds (1), &HwmpRtableTest::TestAddPath, this);
-  Simulator::Schedule (Seconds (2), &HwmpRtableTest::TestPrecursorAdd, this);
-  Simulator::Schedule (expire + Seconds (2), &HwmpRtableTest::TestExpire, this);
-  Simulator::Schedule (expire + Seconds (3), &HwmpRtableTest::TestPrecursorFind, this);
-
-  Simulator::Run ();
-  Simulator::Destroy ();
-
-  return result;
-}
-#endif // RUN_SELF_TESTS
 } //namespace dot11s
 } //namespace ns3
--- a/src/devices/mesh/dot11s/peer-link-frame.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/dot11s/peer-link-frame.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -237,75 +237,6 @@
       && (a.m_meshId.IsEqual (b.m_meshId)) && (a.m_config == b.m_config)
       && (a.m_reasonCode == b.m_reasonCode));
 }
-#ifdef RUN_SELF_TESTS
-/// Built-in self test for PeerLinkFrameStart
-struct PeerLinkFrameStartBist : public Test
-{
-  PeerLinkFrameStartBist () :
-    Test ("Mesh/802.11s/PeerLinkFrameStart")
-  {
-  }
-  virtual bool
-  RunTests ();
-};
-/// Test instance
-static PeerLinkFrameStartBist g_PeerLinkFrameStartBist;
-
-bool
-PeerLinkFrameStartBist::RunTests ()
-{
-  bool result (true);
-    {
-      PeerLinkFrameStart a;
-      PeerLinkFrameStart::PlinkFrameStartFields fields;
-      fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN);
-      fields.capability = 0;
-      fields.aid = 101;
-      fields.reasonCode = 12;
-      fields.meshId = IeMeshId ("qwertyuiop");
-      a.SetPlinkFrameStart (fields);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      PeerLinkFrameStart b;
-      b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_OPEN));
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-    {
-      PeerLinkFrameStart a;
-      PeerLinkFrameStart::PlinkFrameStartFields fields;
-      fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM);
-      fields.capability = 0;
-      fields.aid = 1234;
-      fields.reasonCode = 12;
-      fields.meshId = IeMeshId ("qwerty");
-      a.SetPlinkFrameStart (fields);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      PeerLinkFrameStart b;
-      b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CONFIRM));
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-    {
-      PeerLinkFrameStart a;
-      PeerLinkFrameStart::PlinkFrameStartFields fields;
-      fields.subtype = (uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE);
-      fields.capability = 0;
-      fields.aid = 10;
-      fields.meshId = IeMeshId ("qqq");
-      fields.reasonCode = 12;
-      a.SetPlinkFrameStart (fields);
-      Ptr<Packet> packet = Create<Packet> ();
-      packet->AddHeader (a);
-      PeerLinkFrameStart b;
-      b.SetPlinkFrameSubtype ((uint8_t) (WifiMeshActionHeader::PEER_LINK_CLOSE));
-      packet->RemoveHeader (b);
-      NS_TEST_ASSERT_EQUAL (a, b);
-    }
-  return result;
-}
-#endif
 } // namespace dot11s
 } //namespace ns3
 
--- a/src/devices/mesh/dot11s/wscript	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/dot11s/wscript	Wed Sep 30 20:15:49 2009 +0400
@@ -23,6 +23,7 @@
         'hwmp-protocol-mac.cc',
         'hwmp-protocol.cc',
         'airtime-metric.cc',
+        'dot11s-test-suite.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'dot11s'
--- a/src/devices/mesh/flame/flame-header.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/flame/flame-header.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -20,7 +20,6 @@
 #include "ns3/assert.h"
 #include "ns3/address-utils.h"
 #include "ns3/packet.h"
-#include "ns3/test.h"
 
 #include "flame-header.h"
 
@@ -143,40 +142,5 @@
       == b.m_origSrc) && (a.m_protocol == b.m_protocol));
 }
 
-#ifdef RUN_SELF_TESTS
-
-/// Built-in self test for FlameHeader
-struct FlameHeaderBist : public Test
-{
-  FlameHeaderBist () :
-    Test ("Mesh/Flame/FlameHeader")
-  {
-  }
-  virtual bool
-  RunTests ();
-};
-
-/// Test instance
-static FlameHeaderBist g_FlameHeaderBist;
-
-bool
-FlameHeaderBist::RunTests ()
-{
-  bool result (true);
-  FlameHeader a;
-  a.AddCost (123);
-  a.SetSeqno (456);
-  a.SetOrigDst (Mac48Address ("11:22:33:44:55:66"));
-  a.SetOrigSrc (Mac48Address ("00:11:22:33:44:55"));
-  a.SetProtocol (0x806);
-  Ptr<Packet> packet = Create<Packet> ();
-  packet->AddHeader (a);
-  FlameHeader b;
-  packet->RemoveHeader (b);
-  NS_TEST_ASSERT_EQUAL (b, a);
-  return result;
-}
-#endif
-
 } //namespace flame
 } // namespace ns3
--- a/src/devices/mesh/flame/flame-rtable.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/flame/flame-rtable.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -109,85 +109,5 @@
       && seqnum == 0);
 }
 
-#ifdef RUN_SELF_TESTS
-/// Unit test for FlameRtable
-class FlameRtableTest : public Test
-{
-public:
-  FlameRtableTest ();
-  virtual bool
-  RunTests ();
-
-private:
-  /// Test Add apth and lookup path;
-  void
-  TestLookup ();
-  /**
-   * \name Test add path and try to lookup after entry has expired
-   * \{
-   */
-  void
-  TestAddPath ();
-  void
-  TestExpire ();
-  ///\}
-private:
-  bool result;
-
-  Mac48Address dst;
-  Mac48Address hop;
-  uint32_t iface;
-  uint8_t cost;
-  uint16_t seqnum;
-  Ptr<FlameRtable> table;
-};
-
-/// Test instance
-static FlameRtableTest g_FlameRtableTest;
-
-FlameRtableTest::FlameRtableTest () :
-  Test ("Mesh/Flame/FlameRtable"), result (true), dst ("01:00:00:01:00:01"), hop ("01:00:00:01:00:03"),
-      iface (8010), cost (10), seqnum (1)
-{
-}
-
-void
-FlameRtableTest::TestLookup ()
-{
-  FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
-
-  table->AddPath (dst, hop, iface, cost, seqnum);
-  NS_TEST_ASSERT (table->Lookup (dst) == correct);
-}
-
-void
-FlameRtableTest::TestAddPath ()
-{
-  table->AddPath (dst, hop, iface, cost, seqnum);
-}
-
-void
-FlameRtableTest::TestExpire ()
-{
-  // this is assumed to be called when path records are already expired
-  FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
-  NS_TEST_ASSERT (!table->Lookup (dst).IsValid ());
-}
-bool
-FlameRtableTest::RunTests ()
-{
-  table = CreateObject<FlameRtable> ();
-
-  Simulator::Schedule (Seconds (0), &FlameRtableTest::TestLookup, this);
-  Simulator::Schedule (Seconds (1), &FlameRtableTest::TestAddPath, this);
-  Simulator::Schedule (Seconds (122), &FlameRtableTest::TestExpire, this);
-
-  Simulator::Run ();
-  Simulator::Destroy ();
-
-  return result;
-}
-
-#endif // RUN_SELF_TESTS
 } //namespace flame
 } //namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/flame/flame-test-suite.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -0,0 +1,158 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "ns3/test.h"
+#include "ns3/packet.h"
+#include "ns3/simulator.h"
+#include "flame-header.h"
+#include "flame-rtable.h"
+
+namespace ns3 {
+namespace flame {
+
+/// Built-in self test for FlameHeader
+struct FlameHeaderTest : public TestCase
+{
+  FlameHeaderTest () :
+    TestCase ("FlameHeader roundtrip serialization")
+  {
+  }
+  bool DoRun ();
+};
+
+bool
+FlameHeaderTest::DoRun ()
+{
+  FlameHeader a;
+  a.AddCost (123);
+  a.SetSeqno (456);
+  a.SetOrigDst (Mac48Address ("11:22:33:44:55:66"));
+  a.SetOrigSrc (Mac48Address ("00:11:22:33:44:55"));
+  a.SetProtocol (0x806);
+  Ptr<Packet> packet = Create<Packet> ();
+  packet->AddHeader (a);
+  FlameHeader b;
+  packet->RemoveHeader (b);
+  NS_TEST_ASSERT_MSG_EQ (b, a, "FlameHeader roundtrip serialization works");
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+
+/// Unit test for FlameRtable
+class FlameRtableTest : public TestCase
+{
+public:
+  FlameRtableTest ();
+  bool DoRun ();
+
+private:
+  /// Test Add apth and lookup path;
+  void TestLookup ();
+  /**
+   * \name Test add path and try to lookup after entry has expired
+   * \{
+   */
+  void TestAddPath ();
+  void TestExpire ();
+  ///\}
+private:
+  bool error;
+
+  Mac48Address dst;
+  Mac48Address hop;
+  uint32_t iface;
+  uint8_t cost;
+  uint16_t seqnum;
+  Ptr<FlameRtable> table;
+};
+
+/// Test instance
+static FlameRtableTest g_FlameRtableTest;
+
+FlameRtableTest::FlameRtableTest () :
+  TestCase ("Mesh/Flame/FlameRtable"), 
+  error (false), 
+  dst ("01:00:00:01:00:01"), 
+  hop ("01:00:00:01:00:03"),
+  iface (8010), 
+  cost (10), 
+  seqnum (1)
+{
+}
+
+void
+FlameRtableTest::TestLookup ()
+{
+  FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
+
+  table->AddPath (dst, hop, iface, cost, seqnum);
+  NS_TEST_EXPECT_MSG_EQ ((table->Lookup (dst) == correct), true, "Routing table lookup works");
+}
+
+void
+FlameRtableTest::TestAddPath ()
+{
+  table->AddPath (dst, hop, iface, cost, seqnum);
+}
+
+void
+FlameRtableTest::TestExpire ()
+{
+  // this is assumed to be called when path records are already expired
+  FlameRtable::LookupResult correct (hop, iface, cost, seqnum);
+  NS_TEST_EXPECT_MSG_EQ (table->Lookup (dst).IsValid (), false, "Routing table records expirations works");
+}
+
+bool
+FlameRtableTest::DoRun ()
+{
+  table = CreateObject<FlameRtable> ();
+
+  Simulator::Schedule (Seconds (0), &FlameRtableTest::TestLookup, this);
+  Simulator::Schedule (Seconds (1), &FlameRtableTest::TestAddPath, this);
+  Simulator::Schedule (Seconds (122), &FlameRtableTest::TestExpire, this);
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return GetErrorStatus ();
+}
+
+
+//-----------------------------------------------------------------------------
+
+class FlameTestSuite : public TestSuite
+{
+public:
+  FlameTestSuite ();
+};
+
+FlameTestSuite::FlameTestSuite ()
+  : TestSuite ("devices-mesh-flame", UNIT)
+{
+  AddTestCase (new FlameHeaderTest);
+  AddTestCase (new FlameRtableTest);
+}
+
+FlameTestSuite g_flameTestSuite;
+
+}
+}
--- a/src/devices/mesh/flame/wscript	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/flame/wscript	Wed Sep 30 20:15:49 2009 +0400
@@ -7,6 +7,7 @@
         'flame-rtable.cc',
         'flame-protocol-mac.cc',
         'flame-protocol.cc',
+        'flame-test-suite.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'flame'
--- a/src/devices/mesh/wifi-information-element-vector.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/mesh/wifi-information-element-vector.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -365,26 +365,23 @@
     }
   return true;
 }
-#ifdef RUN_SELF_TESTS
 
-/// Built-in self test for WifiInformationElementVector
-struct WifiInformationElementVectorBist : public Test
+//-----------------------------------------------------------------------------
+// Unit tests
+//-----------------------------------------------------------------------------
+/// Built-in self test for WifiInformationElementVector and all IE
+struct WifiInformationElementVectorBist : public TestCase
 {
   WifiInformationElementVectorBist () :
-    Test ("Mesh/WifiInformationElementVector")
+    TestCase ("Serializarion test for all mesh information elements")
   {
   };
-  virtual bool
-  RunTests ();
+  bool DoRun ();
 };
 
-/// Test instance
-static WifiInformationElementVectorBist g_IePrepBist;
-
 bool
-WifiInformationElementVectorBist::RunTests ()
+WifiInformationElementVectorBist::DoRun ()
 {
-  bool result = true;
   WifiInformationElementVector vector;
   {
     //Mesh ID test
@@ -424,12 +421,12 @@
     rann->SetHopcount (2);
     rann->SetTTL (4);
     rann->DecrementTtl ();
-    NS_TEST_ASSERT_EQUAL (rann->GetTtl (), 3);
+    NS_TEST_ASSERT_MSG_EQ (rann->GetTtl (), 3, "SetTtl works");
     rann->SetOriginatorAddress (Mac48Address ("11:22:33:44:55:66"));
     rann->SetDestSeqNumber (5);
     rann->SetMetric (6);
     rann->IncrementMetric (2);
-    NS_TEST_ASSERT_EQUAL (rann->GetMetric (), 8);
+    NS_TEST_ASSERT_MSG_EQ (rann->GetMetric (), 8, "SetMetric works");
     vector.AddInformationElement (rann);
   }
   {
@@ -475,10 +472,23 @@
   packet->AddHeader (vector);
   WifiInformationElementVector resultVector;
   packet->RemoveHeader (resultVector);
-  NS_TEST_ASSERT (vector == resultVector);
+  NS_TEST_ASSERT_MSG_EQ (vector, resultVector, "Roundtrip serialization of all known information elements works");
   
-  return result;
+  return false;
 }
 
-#endif // RUN_SELF_TESTS
+class MeshTestSuite : public TestSuite
+{
+public:
+  MeshTestSuite ();
+};
+
+MeshTestSuite::MeshTestSuite ()
+  : TestSuite ("devices-mesh", UNIT)
+{
+  AddTestCase (new WifiInformationElementVectorBist);
+}
+
+MeshTestSuite g_meshTestSuite;
+
 } //namespace ns3
--- a/src/devices/point-to-point/point-to-point-channel.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/point-to-point/point-to-point-channel.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -18,6 +18,7 @@
 
 #include "point-to-point-channel.h"
 #include "point-to-point-net-device.h"
+#include "ns3/trace-source-accessor.h"
 #include "ns3/packet.h"
 #include "ns3/simulator.h"
 #include "ns3/log.h"
@@ -38,6 +39,9 @@
                    TimeValue (Seconds (0)),
                    MakeTimeAccessor (&PointToPointChannel::m_delay),
                    MakeTimeChecker ())
+    .AddTraceSource ("TxRxPointToPoint",
+                     "Trace source indicating transmission of packet from the PointToPointChannel, used by the Animation interface.",
+                     MakeTraceSourceAccessor (&PointToPointChannel::m_txrxPointToPoint))
     ;
   return tid;
 }
@@ -93,7 +97,7 @@
     m_link[wire].m_dst, p);
 
   // Call the tx anim callback on the net device
-  src->m_txrxPointToPoint (p, src, m_link[wire].m_dst, txTime, txTime + m_delay);
+  m_txrxPointToPoint (p, src, m_link[wire].m_dst, txTime, txTime + m_delay);
   return true;
 }
 
--- a/src/devices/point-to-point/point-to-point-channel.h	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/point-to-point/point-to-point-channel.h	Wed Sep 30 20:15:49 2009 +0400
@@ -24,6 +24,7 @@
 #include "ns3/ptr.h"
 #include "ns3/nstime.h"
 #include "ns3/data-rate.h"
+#include "ns3/traced-callback.h"
 
 namespace ns3 {
 
@@ -97,6 +98,22 @@
   Time          m_delay;
   int32_t       m_nDevices;
 
+  /**
+   * The trace source for the packet transmission animation events that the 
+   * device can fire.
+   * Arguments to the callback are the packet, transmitting
+   * net device, receiving net device, transmittion time and 
+   * packet receipt time.
+   *
+   * @see class CallBackTraceSource
+   */
+  TracedCallback<Ptr<const Packet>, // Packet being transmitted
+                 Ptr<NetDevice>,    // Transmitting NetDevice
+                 Ptr<NetDevice>,    // Receiving NetDevice
+                 Time,              // Amount of time to transmit the pkt
+                 Time               // Last bit receive time (relative to now)
+                 > m_txrxPointToPoint;
+
   enum WireState
     {
       INITIALIZING,
--- a/src/devices/point-to-point/point-to-point-net-device.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/point-to-point/point-to-point-net-device.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -82,9 +82,6 @@
     // Trace sources at the "top" of the net device, where packets transition
     // to/from higher layers.
     //
-    .AddTraceSource ("TxRxPointToPoint", 
-                     "Trace source indicating transmission of packet from the PointToPointChannel, used by the Animation interface.",
-                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_txrxPointToPoint))
     .AddTraceSource ("MacTx", 
                      "Trace source indicating a packet has arrived for transmission by this device",
                      MakeTraceSourceAccessor (&PointToPointNetDevice::m_macTxTrace))
--- a/src/devices/point-to-point/point-to-point-net-device.h	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/point-to-point/point-to-point-net-device.h	Wed Sep 30 20:15:49 2009 +0400
@@ -387,24 +387,6 @@
   Ptr<ErrorModel> m_receiveErrorModel;
 
   /**
-   * The trace source for the packet transmission animation events that the 
-   * device can fire.
-   * Arguments to the callback are the packet, transmitting
-   * net device, receiving net device, transmittion time and 
-   * packet receipt time.
-   *
-   * @see class CallBackTraceSource
-   */
-  friend class PointToPointChannel; // Allow the channel to call the callback
-  TracedCallback<Ptr<const Packet>, // Packet being transmitted
-                 Ptr<NetDevice>,    // Transmitting NetDevice
-                 Ptr<NetDevice>,    // Receiving NetDevice
-                 Time,              // Amount of time to transmit the pkt
-                 Time               // Last bit receive time (relative to now)
-                 > m_txrxPointToPoint;
-
-
-  /**
    * The trace source fired when packets come into the "top" of the device
    * at the L3/L2 transition, before being queued for transmission.
    *
--- a/src/devices/wifi/dcf-manager-test.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/wifi/dcf-manager-test.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -17,13 +17,11 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#ifdef RUN_SELF_TESTS
 
 #include "ns3/test.h"
 #include "ns3/simulator.h"
 #include "dcf-manager.h"
 
-
 namespace ns3 {
 
 class DcfManagerTest;
@@ -56,11 +54,11 @@
 };
 
 
-class DcfManagerTest : public Test
+class DcfManagerTest : public TestCase
 {
 public:
   DcfManagerTest ();
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 
 
   void NotifyAccessGranted (uint32_t i);
@@ -99,7 +97,6 @@
   DcfManager *m_dcfManager;
   DcfStates m_dcfStates;
   uint32_t m_ackTimeoutValue;
-  bool m_result;
 };
 
 
@@ -135,24 +132,19 @@
 
 
 DcfManagerTest::DcfManagerTest ()
-  : Test ("DcfManager")
+  : TestCase ("DcfManager")
 {}
 
 void 
 DcfManagerTest::NotifyAccessGranted (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedGrants.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants");
   std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
   state->m_expectedGrants.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected access grant is now");
   m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first));
   m_dcfManager->NotifyAckTimeoutStartNow (MicroSeconds (m_ackTimeoutValue + expected.first));
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void
 DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
@@ -165,46 +157,31 @@
 DcfManagerTest::NotifyInternalCollision (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedInternalCollision.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), false, "Have expected internal collisions");
   struct DcfStateTest::ExpectedCollision expected = state->m_expectedInternalCollision.front ();
   state->m_expectedInternalCollision.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected internal collision time is now");
   state->StartBackoffNow (expected.nSlots);
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void 
 DcfManagerTest::NotifyCollision (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
-  NS_TEST_ASSERT (!state->m_expectedCollision.empty ());
+  NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), false, "Have expected collisions");
   struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front ();
   state->m_expectedCollision.pop_front ();
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
+  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected collision is now");
   state->StartBackoffNow (expected.nSlots);
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 void 
 DcfManagerTest::NotifyChannelSwitching (uint32_t i)
 {
   DcfStateTest *state = m_dcfStates[i];
-  bool result = true;
   if (!state->m_expectedGrants.empty ())
     {
       std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
       state->m_expectedGrants.pop_front ();
-      NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
-    }
-  if (!result)
-    {
-      m_result = result;
+      NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected grant is now");
     }
 }
 
@@ -249,23 +226,18 @@
 void
 DcfManagerTest::EndTest (void)
 {
-  bool result = true;
   Simulator::Run ();
   Simulator::Destroy ();
   for (DcfStates::const_iterator i = m_dcfStates.begin (); i != m_dcfStates.end (); i++)
     {
       DcfStateTest *state = *i;
-      NS_TEST_ASSERT (state->m_expectedGrants.empty ());
-      NS_TEST_ASSERT (state->m_expectedInternalCollision.empty ());
-      NS_TEST_ASSERT (state->m_expectedCollision.empty ());
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), true, "Have no expected grants");
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), true, "Have no internal collisions");
+      NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), true, "Have no expected collisions");
       delete state;
     }
   m_dcfStates.clear ();
   delete m_dcfManager;
-  if (!result)
-    {
-      m_result = result;
-    }
 }
 
 void 
@@ -369,10 +341,8 @@
 
 
 bool 
-DcfManagerTest::RunTests (void)
+DcfManagerTest::DoRun (void)
 {
-  m_result = true;
-
   //  0      3       4    5      8       9  10   12
   //  | sifs | aifsn | tx | sifs | aifsn |   | tx | 
   //
@@ -691,15 +661,24 @@
   AddSwitchingEvt(80,20);
   AddAccessRequest (101, 2, 110, 0);
   EndTest ();
-
-
-  return m_result;
+  
+  return GetErrorStatus ();
 }
 
+//-----------------------------------------------------------------------------
 
+class DcfTestSuite : public TestSuite
+{
+public:
+  DcfTestSuite ();
+};
 
-static DcfManagerTest g_dcf_manager_test;
+DcfTestSuite::DcfTestSuite ()
+  : TestSuite ("devices-wifi-dcf", UNIT)
+{
+  AddTestCase (new DcfManagerTest);
+}
+
+DcfTestSuite g_dcfTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/interference-helper-tx-duration-test.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/wifi/interference-helper-tx-duration-test.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -18,26 +18,23 @@
  * Author: Nicola Baldo <nbaldo@cttc.es>
  */
 
-#include<ns3/object.h>
-#include<ns3/log.h>
+#include <ns3/object.h>
+#include <ns3/log.h>
 #include <ns3/test.h>
-#include<iostream>
-#include"interference-helper.h"
-#include"wifi-phy.h"
+#include <iostream>
+#include "interference-helper.h"
+#include "wifi-phy.h"
 
 NS_LOG_COMPONENT_DEFINE ("InterferenceHelperTxDurationTest");
 
-
-#ifdef RUN_SELF_TESTS
-
-
 namespace ns3 {
 
-class InterferenceHelperTxDurationTest : public Test {
+class InterferenceHelperTxDurationTest : public TestCase 
+{
 public:
   InterferenceHelperTxDurationTest ();
   virtual ~InterferenceHelperTxDurationTest ();
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 
 private:
 
@@ -69,12 +66,8 @@
 };
 
 
-// we need to create one instance of InterferenceHelperTxDurationTest
-static InterferenceHelperTxDurationTest interferenceHelperTxDurationTestInstance;
-
-
 InterferenceHelperTxDurationTest::InterferenceHelperTxDurationTest ()
-  : Test ("InterferenceHelperTxDuration")
+  : TestCase ("InterferenceHelper TX Duration")
 {
 }
 
@@ -83,8 +76,6 @@
 {
 }
 
-
-
 bool
 InterferenceHelperTxDurationTest::CheckPayloadDuration(uint32_t size, WifiMode payloadMode, uint32_t knownDurationMicroSeconds)
 {
@@ -119,7 +110,7 @@
 }
 
 bool 
-InterferenceHelperTxDurationTest::RunTests (void)
+InterferenceHelperTxDurationTest::DoRun (void)
 {
   bool retval = true;
 
@@ -182,12 +173,21 @@
     && CheckTxDuration (76, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 32)
     && CheckTxDuration (14, WifiPhy::Get54mba (), WIFI_PREAMBLE_LONG, 24);
 
-
-  return retval;
+  return (!retval);
 }
 
+class TxDurationTestSuite : public TestSuite
+{
+public:
+  TxDurationTestSuite ();
+};
 
+TxDurationTestSuite::TxDurationTestSuite ()
+  : TestSuite ("devices-wifi-tx-duration", UNIT)
+{
+  AddTestCase (new InterferenceHelperTxDurationTest);
+}
+
+TxDurationTestSuite g_txDurationTestSuite;
 } //namespace ns3 
 
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/mac-rx-middle.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/wifi/mac-rx-middle.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -299,54 +299,3 @@
 }
 
 } // namespace ns3
-
-#ifdef RUN_SELF_TESTS
-
-#include "ns3/test.h"
-
-namespace ns3 {
-
-class MacRxMiddleTest : public Test
-{
-public:
-  MacRxMiddleTest () : Test ("MacRxMiddle") {}
-  virtual bool RunTests (void) 
-  {
-    bool result = true;
-    MacRxMiddle middle;
-    // 0 < 1
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (0 << 4, 1 << 4));
-    // 0 < 2047
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (0 << 4, 2047 << 4));
-    // 0 > 2048
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 2048 << 4));
-    // 0 > 2049
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 2049 << 4));
-    // 0 > 4095
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (0 << 4, 4095 << 4));
-
-    // 1 > 0
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (1 << 4, 0 << 4));
-    // 2047 > 0
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (2047 << 4, 0 << 4));
-    // 2048 < 0
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 0 << 4));
-    // 2049 < 0
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2049 << 4, 0 << 4));
-    // 4095 < 0 
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (4095 << 4, 0 << 4));
-
-    // 2048 < 2049
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 2049 << 4));
-    // 2048 < 4095
-    NS_TEST_ASSERT (middle.SequenceControlSmaller (2048 << 4, 4095 << 4));
-    // 2047 > 4095
-    NS_TEST_ASSERT (!middle.SequenceControlSmaller (2047 << 4, 4095 << 4));
-
-    return result;
-  }
-} g_macRxMiddleTest;
-
-} // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/devices/wifi/wifi-phy.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/wifi/wifi-phy.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -391,7 +391,7 @@
 {
   static WifiMode mode = WifiModeFactory::CreateBpsk ("wifi-9mbs-5Mhz",
                                                       false,
-                                                      10000000, 9000000, 12000000,
+                                                      5000000, 9000000, 12000000,
                                                       WIFI_PHY_STANDARD_80211_5Mhz);
   return mode;
 }
@@ -401,7 +401,7 @@
 {
   static WifiMode mode = WifiModeFactory::CreateBpsk ("wifi-12mbs-5Mhz",
                                                       false,
-                                                      10000000, 12000000, 18000000,
+                                                      5000000, 12000000, 18000000,
                                                       WIFI_PHY_STANDARD_80211_5Mhz);
   return mode;
 }
@@ -411,7 +411,7 @@
 {
   static WifiMode mode = WifiModeFactory::CreateBpsk ("wifi-13.5mbs-5Mhz",
                                                       false,
-                                                      10000000, 13500000, 18000000,
+                                                      5000000, 13500000, 18000000,
                                                       WIFI_PHY_STANDARD_80211_5Mhz);
   return mode;
 }
--- a/src/devices/wifi/wifi-test.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/devices/wifi/wifi-test.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -17,7 +17,6 @@
  *
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
-#ifdef RUN_SELF_TESTS
 
 #include "wifi-net-device.h"
 #include "yans-wifi-channel.h"
@@ -34,16 +33,17 @@
 #include "ns3/test.h"
 #include "ns3/object-factory.h"
 #include "dca-txop.h"
+#include "mac-rx-middle.h"
 #include "ns3/pointer.h"
 
 namespace ns3 {
 
-class WifiTest : public Test
+class WifiTest : public TestCase
 {
 public:
   WifiTest ();
 
-  virtual bool RunTests (void);
+  virtual bool DoRun (void);
 private:
   void RunOne (void);
   void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
@@ -55,7 +55,7 @@
 };
 
 WifiTest::WifiTest ()
-  : Test ("Wifi")
+  : TestCase ("Wifi")
 {}
 
 void 
@@ -114,14 +114,11 @@
 }
 
 bool
-WifiTest::RunTests (void)
+WifiTest::DoRun (void)
 {
-  bool result = true;
-
   m_mac.SetTypeId ("ns3::AdhocWifiMac");
   m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
   
-
   m_manager.SetTypeId ("ns3::ArfWifiManager");
   RunOne ();
   m_manager.SetTypeId ("ns3::AarfWifiManager");
@@ -147,12 +144,65 @@
   m_mac.SetTypeId ("ns3::AdhocWifiMac");
   RunOne ();
 
-  return result;
+  return false;
 }
 
-static WifiTest g_wifiTest;
+//-----------------------------------------------------------------------------
+class MacRxMiddleTest : public TestCase
+{
+public:
+  MacRxMiddleTest () : TestCase ("MacRxMiddle") {}
+  virtual bool DoRun (void) 
+  {
+    MacRxMiddle middle;
+    // 0 < 1
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (0 << 4, 1 << 4), true, "0 < 1");
+    // 0 < 2047
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (0 << 4, 2047 << 4), true, "0 < 2047");
+    // 0 > 2048
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 2048 << 4), true, "0 > 2048");
+    // 0 > 2049
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 2049 << 4), true, "0 > 2049");
+    // 0 > 4095
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (0 << 4, 4095 << 4), true, "0 > 4095");
 
+    // 1 > 0
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (1 << 4, 0 << 4), true, "1 > 0");
+    // 2047 > 0
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (2047 << 4, 0 << 4), true, "2047 > 0");
+    // 2048 < 0
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 0 << 4), true, "2048 < 0");
+    // 2049 < 0
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2049 << 4, 0 << 4), true, "2049 < 0");
+    // 4095 < 0 
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (4095 << 4, 0 << 4), true, "4095 < 0");
+
+    // 2048 < 2049
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 2049 << 4), true, "2048 < 2049");
+    // 2048 < 4095
+    NS_TEST_EXPECT_MSG_EQ (middle.SequenceControlSmaller (2048 << 4, 4095 << 4), true, "2048 < 4095");
+    // 2047 > 4095
+    NS_TEST_EXPECT_MSG_EQ (!middle.SequenceControlSmaller (2047 << 4, 4095 << 4), true, "2047 > 4095");
+
+    return GetErrorStatus ();
+  }
+};
+
+//-----------------------------------------------------------------------------
+
+class WifiTestSuite : public TestSuite
+{
+public:
+  WifiTestSuite ();
+};
+
+WifiTestSuite::WifiTestSuite ()
+  : TestSuite ("devices-wifi", UNIT)
+{
+  AddTestCase (new WifiTest);
+  AddTestCase (new MacRxMiddleTest);
+}
+
+WifiTestSuite g_wifiTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/helper/ipv4-address-helper.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/helper/ipv4-address-helper.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -177,120 +177,179 @@
   return 0;
 }
 
-}; // namespace ns3
-
-#ifdef RUN_SELF_TESTS
+} // namespace ns3
 
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class AddressHelperTest : public Test
+class NetworkAllocatorHelperTestCase : public TestCase
 {
 public:
-  AddressHelperTest ();
-  virtual bool RunTests (void);
+  NetworkAllocatorHelperTestCase ();
+private:
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
 };
 
-static AddressHelperTest g_addressHelperTest;
-
-AddressHelperTest::AddressHelperTest ()
-  : Test ("AddressHelper")
-{
-}
+NetworkAllocatorHelperTestCase::NetworkAllocatorHelperTestCase ()
+  : TestCase ("Make sure the network allocator part is working on some common network prefixes.")
+{}
 
-  bool
-AddressHelperTest::RunTests (void)
+void
+NetworkAllocatorHelperTestCase::DoTeardown (void)
 {
-  bool result = true;
-  Ipv4Address network;
+  Ipv4AddressGenerator::Reset ();
+}
+bool
+NetworkAllocatorHelperTestCase::DoRun (void)
+{
   Ipv4Address address;
-
-//
-// Make sure the network allocator part is working on some common network
-// prefixes.
-//
+  Ipv4Address network;
   Ipv4AddressHelper h;
 
   h.SetBase ("1.0.0.0", "255.0.0.0");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("2.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("2.0.0.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("2.0.0.1"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("2.0.0.1"), "XXX");
 
   h.SetBase ("0.1.0.0", "255.255.0.0");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.2.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.2.0.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.2.0.1"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.2.0.1"), "XXX");
 
   h.SetBase ("0.0.1.0", "255.255.255.0");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.2.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.2.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.2.1"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.2.1"), "XXX");
+
+  return false;
+}
+
+class AddressAllocatorHelperTestCase : public TestCase
+{
+public:
+  AddressAllocatorHelperTestCase ();
+private:
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
 
-//
-// Make sure the address allocator part is working.
-//
+AddressAllocatorHelperTestCase::AddressAllocatorHelperTestCase ()
+  : TestCase ("Make sure the address allocator part is working")
+{}
+
+void
+AddressAllocatorHelperTestCase::DoTeardown (void)
+{
+  Ipv4AddressGenerator::Reset ();
+}
+
+bool
+AddressAllocatorHelperTestCase::DoRun (void)
+{
+  Ipv4Address network;
+  Ipv4Address address;
+  Ipv4AddressHelper h;
+
   h.SetBase ("1.0.0.0", "255.0.0.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.4"), "XXX");
 
   h.SetBase ("0.1.0.0", "255.255.0.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.4"), "XXX");
 
   h.SetBase ("0.0.1.0", "255.255.255.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.4"), "XXX");
+
+  return false;
+}
+
+class ResetAllocatorHelperTestCase : public TestCase
+{
+public:
+  ResetAllocatorHelperTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
 
-//
-// Make sure the reset to base behavior is working.  We're going to use some
-// of the same addresses allocated above, so reset the Ipv4AddressGenerator
-// to make it forget we did.
-//
-  Ipv4AddressGenerator::Reset ();
+ResetAllocatorHelperTestCase::ResetAllocatorHelperTestCase ()
+  : TestCase ("Make sure the reset to base behavior is working")
+{}
+
+bool
+ResetAllocatorHelperTestCase::DoRun (void)
+{
+  Ipv4Address network;
+  Ipv4Address address;
+  Ipv4AddressHelper h;
+
+  //
+  // We're going to use some of the same addresses allocated above, 
+  // so reset the Ipv4AddressGenerator to make it forget we did.
+  //
 
   h.SetBase ("1.0.0.0", "255.0.0.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.4"), "XXX");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("2.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("2.0.0.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("2.0.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("2.0.0.3"), "XXX");
 
   h.SetBase ("0.1.0.0", "255.255.0.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.4"), "XXX");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.2.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.2.0.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.2.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.2.0.3"), "XXX");
 
   h.SetBase ("0.0.1.0", "255.255.255.0", "0.0.0.3");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.3"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.4"), "XXX");
   network = h.NewNetwork();
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.2.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.2.0"), "XXX");
   address = h.NewAddress();
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.2.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.2.3"), "XXX");
+
+  return false;
+}
+
+void
+ResetAllocatorHelperTestCase::DoTeardown (void)
+{
+  Ipv4AddressGenerator::Reset ();
+}
 
-  return true;
-}
+static class Ipv4AddressHelperTestSuite : public TestSuite
+{
+public:
+  Ipv4AddressHelperTestSuite ()
+    : TestSuite ("ipv4-address-helper", UNIT) 
+  {
+    AddTestCase (new NetworkAllocatorHelperTestCase ());
+    AddTestCase (new AddressAllocatorHelperTestCase ());
+    AddTestCase (new ResetAllocatorHelperTestCase ());
+  }
+} g_ipv4AddressHelperTestSuite;
 
 } // namespace ns3
 
-#endif /* RUN_SELF_TEST */
--- a/src/node/drop-tail-queue.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/node/drop-tail-queue.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -151,31 +151,26 @@
 
 } // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class DropTailQueueTest: public Test {
+class DropTailQueueTestCase : public TestCase
+{
 public:
-  virtual bool RunTests (void);
-  DropTailQueueTest ();
+  DropTailQueueTestCase ();
+  virtual bool DoRun (void);
 };
 
-
-DropTailQueueTest::DropTailQueueTest ()
-  : Test ("DropTailQueue") {}
-
-
-bool
-DropTailQueueTest::RunTests (void)
+DropTailQueueTestCase::DropTailQueueTestCase ()
+  : TestCase ("Sanity check on the drop tail queue implementation")
+{}
+bool 
+DropTailQueueTestCase::DoRun (void)
 {
-  bool result = true;
-
   Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
-  NS_TEST_ASSERT (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)));
+  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)), true, 
+                         "Verify that we can actually set the attribute");
   
   Ptr<Packet> p1, p2, p3, p4;
   p1 = Create<Packet> ();
@@ -183,43 +178,47 @@
   p3 = Create<Packet> ();
   p4 = Create<Packet> ();
 
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
   queue->Enqueue (p1);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
   queue->Enqueue (p2);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
   queue->Enqueue (p3);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
   queue->Enqueue (p4); // will be dropped
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
 
   Ptr<Packet> p;
 
   p = queue->Dequeue ();
-  NS_TEST_ASSERT (p != 0);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
-  NS_TEST_ASSERT_EQUAL (p->GetUid (), p1->GetUid ());
+  NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the first packet");
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
+  NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p1->GetUid (), "was this the first packet ?");
 
   p = queue->Dequeue ();
-  NS_TEST_ASSERT (p != 0);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
-  NS_TEST_ASSERT_EQUAL (p->GetUid (), p2->GetUid ());
+  NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the second packet");
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
+  NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p2->GetUid (), "Was this the second packet ?");
+
+  p = queue->Dequeue ();
+  NS_TEST_EXPECT_MSG_EQ ((p != 0), true, "I want to remove the third packet");
+  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
+  NS_TEST_EXPECT_MSG_EQ (p->GetUid (), p3->GetUid (), "Was this the third packet ?");
 
   p = queue->Dequeue ();
-  NS_TEST_ASSERT (p != 0);
-  NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
-  NS_TEST_ASSERT_EQUAL (p->GetUid (), p3->GetUid ());
+  NS_TEST_EXPECT_MSG_EQ ((p == 0), true, "There are really no packets in there");
 
-  p = queue->Dequeue ();
-  NS_TEST_ASSERT (p == 0);
-
-  return result;
+  return false;
 }
 
-
-static DropTailQueueTest gDropTailQueueTest;
+static class DropTailQueueTestSuite : public TestSuite
+{
+public:
+  DropTailQueueTestSuite ()
+    : TestSuite ("drop-tail-queue", UNIT)
+  {
+    AddTestCase (new DropTailQueueTestCase ());
+  }
+} g_dropTailQueueTestSuite;
 
-}; // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
-
+} // namespace ns3
--- a/src/node/ipv4-address-generator.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/node/ipv4-address-generator.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -457,156 +457,248 @@
     ->TestMode ();
 }
 
-}; // namespace ns3
-
-#ifdef RUN_SELF_TESTS
+} // namespace ns3
 
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class Ipv4AddressGeneratorTest : public Test
+class NetworkNumberAllocatorTestCase : public TestCase
 {
 public:
-  Ipv4AddressGeneratorTest ();
-  virtual bool RunTests (void);
+  NetworkNumberAllocatorTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
 };
 
-Ipv4AddressGeneratorTest::Ipv4AddressGeneratorTest ()
-  : Test ("Ipv4AddressGenerator")
-{
-}
-
-  bool
-Ipv4AddressGeneratorTest::RunTests (void)
+NetworkNumberAllocatorTestCase::NetworkNumberAllocatorTestCase ()
+  : TestCase ("Make sure the network number allocator is working on some of network prefixes.")
+{}
+void 
+NetworkNumberAllocatorTestCase::DoTeardown (void)
 {
-  bool result = true;
+  Ipv4AddressGenerator::Reset ();
+}
+bool 
+NetworkNumberAllocatorTestCase::DoRun (void)
+{
   Ipv4Address network;
-  Ipv4Address address;
-//
-// Make sure the network number allocator is working on some of the network
-// prefixes.
-//
   Ipv4AddressGenerator::Init (Ipv4Address ("1.0.0.0"), Ipv4Mask ("255.0.0.0"),
     Ipv4Address ("0.0.0.0"));
   network = Ipv4AddressGenerator::GetNetwork (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("1.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("1.0.0.0"), "XXX");
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("2.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("2.0.0.0"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.1.0.0"), 
     Ipv4Mask ("255.255.0.0"), Ipv4Address ("0.0.0.0"));
   network = Ipv4AddressGenerator::GetNetwork (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.1.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.1.0.0"), "XXX");
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.2.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.2.0.0"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.0.1.0"),
     Ipv4Mask ("255.255.255.0"), Ipv4Address ("0.0.0.0"));
   network = Ipv4AddressGenerator::GetNetwork (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.1.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.1.0"), "XXX");
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.2.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.2.0"), "XXX");
 
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("3.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("3.0.0.0"), "XXX");
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.3.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.3.0.0"), "XXX");
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.3.0"));
-//
-// Make sure the address allocator is working.
-//
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.3.0"), "XXX");
+
+  return false;
+}
+
+class AddressAllocatorTestCase : public TestCase
+{
+public:
+  AddressAllocatorTestCase ();
+private:
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
+
+AddressAllocatorTestCase::AddressAllocatorTestCase ()
+  : TestCase ("Sanity check on allocation of addresses")
+{}
+
+bool
+AddressAllocatorTestCase::DoRun (void)
+{
+  Ipv4Address address;
+
   Ipv4AddressGenerator::Init (Ipv4Address ("1.0.0.0"), Ipv4Mask ("255.0.0.0"),
     Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("1.0.0.4"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.1.0.0"),
     Ipv4Mask ("255.255.0.0"), Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.1.0.4"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.0.1.0"),
     Ipv4Mask ("255.255.255.0"), Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.4"));
-//
-// Make sure they both play together.
-//
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.1.4"), "XXX");
+
+  return false;
+}
+
+void 
+AddressAllocatorTestCase::DoTeardown (void)
+{
+  Ipv4AddressGenerator::Reset ();
+}
+
+
+class NetworkAndAddressTestCase : public TestCase
+{
+public:
+  NetworkAndAddressTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
+
+NetworkAndAddressTestCase::NetworkAndAddressTestCase ()
+  : TestCase ("Make sure Network and address allocation play together.")
+{}
+
+void 
+NetworkAndAddressTestCase::DoTeardown (void)
+{
+  Ipv4AddressGenerator::Reset ();
+}
+
+bool
+NetworkAndAddressTestCase::DoRun (void)
+{
+  Ipv4Address address;
+  Ipv4Address network;
+
   Ipv4AddressGenerator::Init (Ipv4Address ("3.0.0.0"), Ipv4Mask ("255.0.0.0"),
     Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("3.0.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("3.0.0.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("3.0.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("3.0.0.4"), "XXX");
 
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("4.0.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("4.0.0.0"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.0.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("4.0.0.5"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("4.0.0.5"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.3.0.0"), 
     Ipv4Mask ("255.255.0.0"), Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.3.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.3.0.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.3.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.3.0.4"), "XXX");
 
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.4.0.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.4.0.0"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.0.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.4.0.5"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.4.0.5"), "XXX");
 
   Ipv4AddressGenerator::Init (Ipv4Address ("0.0.3.0"),
     Ipv4Mask ("255.255.255.0"), Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.3.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.3.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.3.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.3.4"), "XXX");
 
   network = Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.4.0"));
+  NS_TEST_EXPECT_MSG_EQ (network, Ipv4Address ("0.0.4.0"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.4.5"));
-//
-// A quick kindof-semi-almost-real example.  First, initialize our /24 network
-// to 192.168.0.0 and begin allocating with ip address 0.0.0.3 out of that
-// prefix.
-//
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("0.0.4.5"), "XXX");
+  return false;
+}
+
+class ExampleAddressGeneratorTestCase : public TestCase
+{
+public:
+  ExampleAddressGeneratorTestCase ();
+private:
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
+
+ExampleAddressGeneratorTestCase::ExampleAddressGeneratorTestCase ()
+  : TestCase ("A quick kindof-semi-almost-real example")
+{}
+
+void
+ExampleAddressGeneratorTestCase::DoTeardown (void)
+{
+  Ipv4AddressGenerator::Reset ();
+}
+
+bool
+ExampleAddressGeneratorTestCase::DoRun (void)
+{
+  Ipv4Address address;
+  //
+  // First, initialize our /24 network to 192.168.0.0 and begin 
+  // allocating with ip address 0.0.0.3 out of that prefix.
+  //
   Ipv4AddressGenerator::Init (Ipv4Address ("192.168.0.0"),
     Ipv4Mask ("255.255.255.0"), Ipv4Address ("0.0.0.3"));
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("192.168.0.3"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("192.168.0.3"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("192.168.0.4"));
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("192.168.0.4"), "XXX");
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("192.168.0.5"));
-//
-// Allocate the next network out of our /24 network (this should be 
-// 192.168.1.0) and begin allocating with IP address 0.0.0.3 out of that
-// prefix.
-//
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("192.168.0.5"), "XXX");
+  //
+  // Allocate the next network out of our /24 network (this should be 
+  // 192.168.1.0) and begin allocating with IP address 0.0.0.3 out of that
+  // prefix.
+  //
   Ipv4AddressGenerator::NextNetwork (Ipv4Mask ("255.255.255.0"));
   Ipv4AddressGenerator::InitAddress (Ipv4Address ("0.0.0.3"),
     Ipv4Mask ("255.255.255.0"));
-//
-// The first address we should get is the previous numbers ORed together, which
-// is 192.168.1.3, of course.
-//
+  //
+  // The first address we should get is the previous numbers ORed together, which
+  // is 192.168.1.3, of course.
+  //
   address = Ipv4AddressGenerator::NextAddress (Ipv4Mask ("255.255.255.0"));
-  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("192.168.1.3"));
-//
-// Make sure that the address collision logic works.
-//
+  NS_TEST_EXPECT_MSG_EQ (address, Ipv4Address ("192.168.1.3"), "XXX");
+
+  return false;
+}
+
+class AddressCollisionTestCase : public TestCase
+{
+public:
+  AddressCollisionTestCase ();
+private:
+  bool DoRun (void);
+  void DoTeardown (void);
+};
+
+AddressCollisionTestCase::AddressCollisionTestCase ()
+  : TestCase ("Make sure that the address collision logic works.")
+{}
+
+void
+AddressCollisionTestCase::DoTeardown (void)
+{
   Ipv4AddressGenerator::Reset ();
-
+}
+bool
+AddressCollisionTestCase::DoRun (void)
+{
   Ipv4AddressGenerator::AddAllocated ("0.0.0.5");
   Ipv4AddressGenerator::AddAllocated ("0.0.0.10");
   Ipv4AddressGenerator::AddAllocated ("0.0.0.15");
@@ -634,27 +726,37 @@
 
   Ipv4AddressGenerator::TestMode ();
   bool added = Ipv4AddressGenerator::AddAllocated ("0.0.0.21");
-  NS_TEST_ASSERT_EQUAL (added, true);
+  NS_TEST_EXPECT_MSG_EQ (added, true, "XXX");
 
   added = Ipv4AddressGenerator::AddAllocated ("0.0.0.4");
-  NS_TEST_ASSERT_EQUAL (added, false);
+  NS_TEST_EXPECT_MSG_EQ (added, false, "XXX");
 
   added = Ipv4AddressGenerator::AddAllocated ("0.0.0.9");
-  NS_TEST_ASSERT_EQUAL (added, false);
+  NS_TEST_EXPECT_MSG_EQ (added, false, "XXX");
 
   added = Ipv4AddressGenerator::AddAllocated ("0.0.0.16");
-  NS_TEST_ASSERT_EQUAL (added, false);
+  NS_TEST_EXPECT_MSG_EQ (added, false, "XXX");
 
   added = Ipv4AddressGenerator::AddAllocated ("0.0.0.21");
-  NS_TEST_ASSERT_EQUAL (added, false);
+  NS_TEST_EXPECT_MSG_EQ (added, false, "XXX");
 
-  Ipv4AddressGenerator::Reset ();
-
-  return result;
+  return false;
 }
 
-static Ipv4AddressGeneratorTest g_addressGeneratorTest;
+
+static class Ipv4AddressGeneratorTestSuite : public TestSuite
+{
+public:
+  Ipv4AddressGeneratorTestSuite ()
+    : TestSuite ("ipv4-address-generator")
+  {
+    AddTestCase (new NetworkNumberAllocatorTestCase ());
+    AddTestCase (new AddressAllocatorTestCase ());
+    AddTestCase (new NetworkAndAddressTestCase ());
+    AddTestCase (new ExampleAddressGeneratorTestCase ());
+    AddTestCase (new AddressCollisionTestCase ());
+  }
+} g_ipv4AddressGeneratorTestSuite;
 
 } // namespace ns3
 
-#endif /* RUN_SELF_TEST */
--- a/src/routing/global-routing/global-route-manager-impl.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/routing/global-routing/global-route-manager-impl.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -1971,40 +1971,26 @@
 
 } // namespace ns3
 
-#ifdef RUN_SELF_TESTS
-
-// ---------------------------------------------------------------------------
-//
-// Unit Tests
-//
-// ---------------------------------------------------------------------------
 
 #include "ns3/test.h"
 #include "ns3/simulator.h"
-#include <stdlib.h> // for rand ()
+#include <stdlib.h> // for rand()
 
 namespace ns3 {
 
-class GlobalRouteManagerImplTest : public Test {
+class GlobalRouteManagerImplTestCase : public TestCase
+{
 public:
-  GlobalRouteManagerImplTest ();
-  virtual ~GlobalRouteManagerImplTest ();
-  virtual bool RunTests (void);
+  GlobalRouteManagerImplTestCase();
+  virtual bool DoRun(void);
 };
 
-GlobalRouteManagerImplTest::GlobalRouteManagerImplTest ()
-  : Test ("GlobalRouteManagerImpl")
-{
-}
-
-GlobalRouteManagerImplTest::~GlobalRouteManagerImplTest ()
+GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase()
+  : TestCase("GlobalRouteManagerImplTestCase")
 {}
-
-  bool
-GlobalRouteManagerImplTest::RunTests (void)
+bool 
+GlobalRouteManagerImplTestCase::DoRun(void)
 {
-  bool ok = true;
-
   CandidateQueue candidate;
 
   for (int i = 0; i < 100; ++i)
@@ -2021,7 +2007,8 @@
       SPFVertex *v = candidate.Pop ();
       if (v->GetDistanceFromRoot () < lastDistance)
         {
-          ok = false;
+          // XXX
+          SetErrorStatus (false);
         }
       lastDistance = v->GetDistanceFromRoot ();
       delete v;
@@ -2176,12 +2163,19 @@
   // all of the LSAs, which each destroys the attached LinkRecords.
   delete srm;
 
-  return ok;
+  // XXX
+  return false;
 }
 
-// Instantiate this class for the unit tests
-static GlobalRouteManagerImplTest g_globalRouteManagerTest;
+
+static class GlobalRouteManagerImplTestSuite : public TestSuite
+{
+public:
+  GlobalRouteManagerImplTestSuite()
+    : TestSuite("global-route-manager-impl", UNIT)
+  {
+    AddTestCase(new GlobalRouteManagerImplTestCase());
+  }
+} g_globalRoutingManagerImplTestSuite;
 
 } // namespace ns3
-
-#endif 
--- a/src/routing/list-routing/ipv4-list-routing.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/routing/list-routing/ipv4-list-routing.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -313,8 +313,6 @@
 
 } // namespace ns3
 
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
 #include "ipv4-list-routing.h"
 #include "ns3/ipv4-routing-protocol.h"
@@ -347,19 +345,49 @@
   void SetIpv4 (Ptr<Ipv4> ipv4) {}
 };
 
-class Ipv4ListRoutingTest: public Test {
+class Ipv4ListRoutingNegativeTestCase : public TestCase
+{
 public:
-  virtual bool RunTests (void);
-  Ipv4ListRoutingTest ();
+  Ipv4ListRoutingNegativeTestCase();
+  virtual bool DoRun (void);
 };
 
-Ipv4ListRoutingTest::Ipv4ListRoutingTest ()
-  : Test ("Ipv4ListRouting") {}
+Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase()
+  : TestCase("Check negative priorities")
+{}
+bool 
+Ipv4ListRoutingNegativeTestCase::DoRun (void)
+{
+  Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
+  Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
+  Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
+  // The Ipv4BRouting should be added with higher priority (larger integer value)
+  lr->AddRoutingProtocol (aRouting, -10);
+  lr->AddRoutingProtocol (bRouting, -5);
+  int16_t first = 3;
+  uint32_t num = lr->GetNRoutingProtocols ();
+  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
+  Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
+  NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
 
-bool
-Ipv4ListRoutingTest::RunTests (void)
+  // XXX
+  return false;
+}
+
+class Ipv4ListRoutingPositiveTestCase : public TestCase
 {
-  bool result = true;
+public:
+  Ipv4ListRoutingPositiveTestCase();
+  virtual bool DoRun (void);
+};
+
+Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase()
+  : TestCase("Check positive priorities")
+{}
+bool 
+Ipv4ListRoutingPositiveTestCase::DoRun (void)
+{
   Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
   Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
   Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
@@ -370,30 +398,30 @@
   int16_t first = 3;
   int16_t second = 3;
   uint32_t num = lr->GetNRoutingProtocols ();
-  NS_TEST_ASSERT_EQUAL (num, 2);
+  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
   Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
-  NS_TEST_ASSERT_EQUAL (10, first);
-  NS_TEST_ASSERT_EQUAL (firstRp, aRouting);
+  NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
   Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
-  NS_TEST_ASSERT_EQUAL (5, second);
-  NS_TEST_ASSERT_EQUAL (secondRp, bRouting);
-
-  // Test negative values
-  lr = CreateObject<Ipv4ListRouting> ();
-  // The Ipv4BRouting should be added with higher priority (larger integer value)
-  lr->AddRoutingProtocol (aRouting, -10);
-  lr->AddRoutingProtocol (bRouting, -5);
-  num = lr->GetNRoutingProtocols ();
-  NS_TEST_ASSERT_EQUAL (num, 2);
-  firstRp = lr->GetRoutingProtocol (0, first);
-  NS_TEST_ASSERT_EQUAL (-5, first);
-  NS_TEST_ASSERT_EQUAL (firstRp, bRouting);
+  NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
   
-  return result;
+  // XXX
+  return false;
 }
 
-static Ipv4ListRoutingTest gIpv4ListRoutingTest;
+static class Ipv4ListRoutingTestSuite : public TestSuite
+{
+public:
+  Ipv4ListRoutingTestSuite()
+    : TestSuite("ipv4-list-routing", UNIT)
+  {
+    AddTestCase(new Ipv4ListRoutingPositiveTestCase());
+    AddTestCase(new Ipv4ListRoutingNegativeTestCase());
+  }
+
+} g_ipv4ListRoutingTestSuite;
 
 } // namespace ns3
 
-#endif /* RUN_SELF_TESTS */
+
--- a/src/routing/list-routing/ipv6-list-routing.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/routing/list-routing/ipv6-list-routing.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -333,7 +333,6 @@
 
 } // namespace ns3
 
-#ifdef RUN_SELF_TESTS
 
 #include "ns3/test.h"
 #include "ipv6-list-routing.h"
@@ -351,7 +350,8 @@
   void NotifyInterfaceDown (uint32_t interface) {}
   void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
   void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
-  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ()) {}
+  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
+                          GetZero ()) {}
   void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
   void SetIpv6 (Ptr<Ipv6> ipv6) {}
 };
@@ -366,24 +366,55 @@
   void NotifyInterfaceDown (uint32_t interface) {}
   void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
   void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
-  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ()) {}
+  void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
+                          GetZero ()) {}
   void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
   void SetIpv6 (Ptr<Ipv6> ipv6) {}
 };
 
-class Ipv6ListRoutingTest: public Test {
+class Ipv6ListRoutingNegativeTestCase : public TestCase
+{
 public:
-  virtual bool RunTests (void);
-  Ipv6ListRoutingTest ();
+  Ipv6ListRoutingNegativeTestCase();
+  virtual bool DoRun (void);
 };
 
-Ipv6ListRoutingTest::Ipv6ListRoutingTest ()
-  : Test ("Ipv6ListRouting") {}
+Ipv6ListRoutingNegativeTestCase::Ipv6ListRoutingNegativeTestCase()
+  : TestCase("Check negative priorities")
+{}
+bool 
+Ipv6ListRoutingNegativeTestCase::DoRun (void)
+{
+  Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
+  Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
+  Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
+  // The Ipv6BRouting should be added with higher priority (larger integer value)
+  lr->AddRoutingProtocol (aRouting, -10);
+  lr->AddRoutingProtocol (bRouting, -5);
+  int16_t first = 3;
+  uint32_t num = lr->GetNRoutingProtocols ();
+  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
+  Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
+  NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
 
-bool
-Ipv6ListRoutingTest::RunTests (void)
+  // XXX
+  return false;
+}
+
+class Ipv6ListRoutingPositiveTestCase : public TestCase
 {
-  bool result = true;
+public:
+  Ipv6ListRoutingPositiveTestCase();
+  virtual bool DoRun (void);
+};
+
+Ipv6ListRoutingPositiveTestCase::Ipv6ListRoutingPositiveTestCase()
+  : TestCase("Check positive priorities")
+{}
+bool 
+Ipv6ListRoutingPositiveTestCase::DoRun (void)
+{
   Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
   Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
   Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
@@ -394,30 +425,28 @@
   int16_t first = 3;
   int16_t second = 3;
   uint32_t num = lr->GetNRoutingProtocols ();
-  NS_TEST_ASSERT_EQUAL (num, 2);
+  NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
   Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
-  NS_TEST_ASSERT_EQUAL (10, first);
-  NS_TEST_ASSERT_EQUAL (firstRp, aRouting);
+  NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
   Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
-  NS_TEST_ASSERT_EQUAL (5, second);
-  NS_TEST_ASSERT_EQUAL (secondRp, bRouting);
-
-  // Test negative values
-  lr = CreateObject<Ipv6ListRouting> ();
-  // The Ipv6BRouting should be added with higher priority (larger integer value)
-  lr->AddRoutingProtocol (aRouting, -10);
-  lr->AddRoutingProtocol (bRouting, -5);
-  num = lr->GetNRoutingProtocols ();
-  NS_TEST_ASSERT_EQUAL (num, 2);
-  firstRp = lr->GetRoutingProtocol (0, first);
-  NS_TEST_ASSERT_EQUAL (-5, first);
-  NS_TEST_ASSERT_EQUAL (firstRp, bRouting);
+  NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
   
-  return result;
+  // XXX
+  return false;
 }
 
-static Ipv6ListRoutingTest gIpv6ListRoutingTest;
+static class Ipv6ListRoutingTestSuite : public TestSuite
+{
+public:
+  Ipv6ListRoutingTestSuite()
+    : TestSuite("ipv6-list-routing", UNIT)
+  {
+    AddTestCase(new Ipv6ListRoutingPositiveTestCase());
+    AddTestCase(new Ipv6ListRoutingNegativeTestCase());
+  }
+
+} g_ipv6ListRoutingTestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/routing/olsr/olsr-header.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/routing/olsr/olsr-header.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -499,259 +499,300 @@
   return messageSize;
 }
 
-
-
 }} // namespace olsr, ns3
 
-
-#ifdef RUN_SELF_TESTS
-
-
 #include "ns3/test.h"
 #include "ns3/packet.h"
-#include <math.h>
-
 
 namespace ns3 {
 
-class OlsrHeaderTest : public ns3::Test {
-private:
+class OlsrEmfTestCase : public TestCase {
 public:
-  OlsrHeaderTest ();
-  virtual bool RunTests (void);
-
-
+  OlsrEmfTestCase ();
+  virtual bool DoRun (void);
 };
 
-OlsrHeaderTest::OlsrHeaderTest ()
-  : ns3::Test ("OlsrHeader")
+OlsrEmfTestCase::OlsrEmfTestCase ()
+  : TestCase ("Check Emf olsr time conversion")
 {}
-
-
 bool 
-OlsrHeaderTest::RunTests (void)
+OlsrEmfTestCase::DoRun (void)
 {
-  bool result = true;
-
-  // Testing packet header + message header + MID message
-  {
-    Packet packet;
-
-    {
-      olsr::PacketHeader hdr;
-      olsr::MessageHeader msg1;
-      olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
-      olsr::MessageHeader msg2;
-      olsr::MessageHeader::Mid &mid2 = msg2.GetMid ();
-    
-      // MID message #1
-      {
-        std::vector<Ipv4Address> &addresses = mid1.interfaceAddresses;
-        addresses.clear ();
-        addresses.push_back (Ipv4Address ("1.2.3.4"));
-        addresses.push_back (Ipv4Address ("1.2.3.5"));
-      }
-
-      msg1.SetTimeToLive (255);
-      msg1.SetOriginatorAddress (Ipv4Address ("11.22.33.44"));
-      msg1.SetVTime (Seconds (9));
-      msg1.SetMessageSequenceNumber (7);
-
-      // MID message #2
-      {
-        std::vector<Ipv4Address> &addresses = mid2.interfaceAddresses;
-        addresses.clear ();
-        addresses.push_back (Ipv4Address ("2.2.3.4"));
-        addresses.push_back (Ipv4Address ("2.2.3.5"));
-      }
-
-      msg2.SetTimeToLive (254);
-      msg2.SetOriginatorAddress (Ipv4Address ("12.22.33.44"));
-      msg2.SetVTime (Seconds (10));
-      msg2.SetMessageType (olsr::MessageHeader::MID_MESSAGE);
-      msg2.SetMessageSequenceNumber (7);
-
-      // Build an OLSR packet header
-      hdr.SetPacketLength (hdr.GetSerializedSize () + msg1.GetSerializedSize () + msg2.GetSerializedSize ());
-      hdr.SetPacketSequenceNumber (123);
-    
-
-      // Now add all the headers in the correct order
-      packet.AddHeader (msg2);
-      packet.AddHeader (msg1);
-      packet.AddHeader (hdr);
-    }    
-
-    {
-      olsr::PacketHeader hdr;
-      packet.RemoveHeader (hdr);
-      NS_TEST_ASSERT_EQUAL (hdr.GetPacketSequenceNumber (), 123);
-      uint32_t sizeLeft = hdr.GetPacketLength () - hdr.GetSerializedSize ();
-      {
-        olsr::MessageHeader msg1;
-
-        packet.RemoveHeader (msg1);
-
-        NS_TEST_ASSERT_EQUAL (msg1.GetTimeToLive (),  255);
-        NS_TEST_ASSERT_EQUAL (msg1.GetOriginatorAddress (), Ipv4Address ("11.22.33.44"));
-        NS_TEST_ASSERT_EQUAL (msg1.GetVTime (), Seconds (9));
-        NS_TEST_ASSERT_EQUAL (msg1.GetMessageType (), olsr::MessageHeader::MID_MESSAGE);
-        NS_TEST_ASSERT_EQUAL (msg1.GetMessageSequenceNumber (), 7);
-
-        olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
-        NS_TEST_ASSERT_EQUAL (mid1.interfaceAddresses.size (), 2);
-        NS_TEST_ASSERT_EQUAL (*mid1.interfaceAddresses.begin (), Ipv4Address ("1.2.3.4"));
-
-        sizeLeft -= msg1.GetSerializedSize ();
-        NS_TEST_ASSERT (sizeLeft > 0);
-      }
-      {
-        // now read the second message
-        olsr::MessageHeader msg2;
-
-        packet.RemoveHeader (msg2);
-
-        NS_TEST_ASSERT_EQUAL (msg2.GetTimeToLive (),  254);
-        NS_TEST_ASSERT_EQUAL (msg2.GetOriginatorAddress (), Ipv4Address ("12.22.33.44"));
-        NS_TEST_ASSERT_EQUAL (msg2.GetVTime (), Seconds (10));
-        NS_TEST_ASSERT_EQUAL (msg2.GetMessageType (), olsr::MessageHeader::MID_MESSAGE);
-        NS_TEST_ASSERT_EQUAL (msg2.GetMessageSequenceNumber (), 7);
-
-        olsr::MessageHeader::Mid mid2 = msg2.GetMid ();
-        NS_TEST_ASSERT_EQUAL (mid2.interfaceAddresses.size (), 2);
-        NS_TEST_ASSERT_EQUAL (*mid2.interfaceAddresses.begin (), Ipv4Address ("2.2.3.4"));
-
-        sizeLeft -= msg2.GetSerializedSize ();
-        NS_TEST_ASSERT_EQUAL (sizeLeft, 0);
-      }
-    }
-  }
-  
-  // Test the HELLO message
-  {
-    Packet packet;
-    olsr::MessageHeader msgIn;
-    olsr::MessageHeader::Hello &helloIn = msgIn.GetHello ();
-
-    helloIn.SetHTime (Seconds (7));
-    helloIn.willingness = 66;
-
-    {
-      olsr::MessageHeader::Hello::LinkMessage lm1;
-      lm1.linkCode = 2;
-      lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.4"));
-      lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.5"));
-      helloIn.linkMessages.push_back (lm1);
-
-      olsr::MessageHeader::Hello::LinkMessage lm2;
-      lm2.linkCode = 3;
-      lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.4"));
-      lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.5"));
-      helloIn.linkMessages.push_back (lm2);
-    }
-
-    packet.AddHeader (msgIn);
-
-    olsr::MessageHeader msgOut;
-    packet.RemoveHeader (msgOut);
-    olsr::MessageHeader::Hello &helloOut = msgOut.GetHello ();
-    
-    NS_TEST_ASSERT_EQUAL (helloOut.GetHTime (), Seconds (7));
-    NS_TEST_ASSERT_EQUAL (helloOut.willingness, 66);
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages.size (), 2);
-
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[0].linkCode, 2);
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[0].neighborInterfaceAddresses[0],
-                          Ipv4Address ("1.2.3.4"));
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[0].neighborInterfaceAddresses[1],
-                          Ipv4Address ("1.2.3.5"));
-
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[1].linkCode, 3);
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[1].neighborInterfaceAddresses[0],
-                          Ipv4Address ("2.2.3.4"));
-    NS_TEST_ASSERT_EQUAL (helloOut.linkMessages[1].neighborInterfaceAddresses[1],
-                          Ipv4Address ("2.2.3.5"));
-
-    // check that all bytes of the message were read
-    NS_TEST_ASSERT_EQUAL (packet.GetSize (), 0);
-  }
-
-  // Test the TC message
-  {
-    Packet packet;
-    olsr::MessageHeader msgIn;
-    olsr::MessageHeader::Tc &tcIn = msgIn.GetTc ();
-
-    tcIn.ansn = 0x1234;
-    tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.4"));
-    tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.5"));
-    packet.AddHeader (msgIn);
-
-    olsr::MessageHeader msgOut;
-    packet.RemoveHeader (msgOut);
-    olsr::MessageHeader::Tc &tcOut = msgOut.GetTc ();
-    
-    NS_TEST_ASSERT_EQUAL (tcOut.ansn, 0x1234);
-    NS_TEST_ASSERT_EQUAL (tcOut.neighborAddresses.size (), 2);
-
-    NS_TEST_ASSERT_EQUAL (tcOut.neighborAddresses[0],
-                          Ipv4Address ("1.2.3.4"));
-    NS_TEST_ASSERT_EQUAL (tcOut.neighborAddresses[1],
-                          Ipv4Address ("1.2.3.5"));
-
-    // check that all bytes of the message were read
-    NS_TEST_ASSERT_EQUAL (packet.GetSize (), 0);
-  }
-
-  // Test the HNA message
-  {
-    Packet packet;
-    olsr::MessageHeader msgIn;
-    olsr::MessageHeader::Hna &hnaIn = msgIn.GetHna ();
-
-    hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
-                                  { Ipv4Address ("1.2.3.4"), Ipv4Mask ("255.255.255.0")});
-    hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
-                                  {Ipv4Address ("1.2.3.5"), Ipv4Mask ("255.255.0.0")});
-    packet.AddHeader (msgIn);
-
-    olsr::MessageHeader msgOut;
-    packet.RemoveHeader (msgOut);
-    olsr::MessageHeader::Hna &hnaOut = msgOut.GetHna ();
-    
-    NS_TEST_ASSERT_EQUAL (hnaOut.associations.size (), 2);
-
-    NS_TEST_ASSERT_EQUAL (hnaOut.associations[0].address,
-                          Ipv4Address ("1.2.3.4"));
-    NS_TEST_ASSERT_EQUAL (hnaOut.associations[0].mask,
-                          Ipv4Mask ("255.255.255.0"));
-
-    NS_TEST_ASSERT_EQUAL (hnaOut.associations[1].address,
-                          Ipv4Address ("1.2.3.5"));
-    NS_TEST_ASSERT_EQUAL (hnaOut.associations[1].mask,
-                          Ipv4Mask ("255.255.0.0"));
-
-    // check that all bytes of the message were read
-    NS_TEST_ASSERT_EQUAL (packet.GetSize (), 0);
-  }
-
   for (int time = 1; time <= 30; time++)
     {
       uint8_t emf = olsr::SecondsToEmf (time);
       double seconds = olsr::EmfToSeconds (emf);
-      if (seconds < 0 || fabs (seconds - time) > 0.1)
-        {
-          result = false;
-          Failure () << "In " << time << " out " << seconds << std::endl;
-        }
+      NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), false,
+                            "XXX");
+    }
+  return false;
+}
+
+
+class OlsrMidTestCase : public TestCase {
+public:
+  OlsrMidTestCase ();
+  virtual bool DoRun (void);
+};
+
+OlsrMidTestCase::OlsrMidTestCase ()
+  : TestCase ("Check Mid olsr messages")
+{}
+bool 
+OlsrMidTestCase::DoRun (void)
+{
+  Packet packet;
+
+  {
+    olsr::PacketHeader hdr;
+    olsr::MessageHeader msg1;
+    olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
+    olsr::MessageHeader msg2;
+    olsr::MessageHeader::Mid &mid2 = msg2.GetMid ();
+    
+    // MID message #1
+    {
+      std::vector<Ipv4Address> &addresses = mid1.interfaceAddresses;
+      addresses.clear ();
+      addresses.push_back (Ipv4Address ("1.2.3.4"));
+      addresses.push_back (Ipv4Address ("1.2.3.5"));
+    }
+
+    msg1.SetTimeToLive (255);
+    msg1.SetOriginatorAddress (Ipv4Address ("11.22.33.44"));
+    msg1.SetVTime (Seconds (9));
+    msg1.SetMessageSequenceNumber (7);
+
+    // MID message #2
+    {
+      std::vector<Ipv4Address> &addresses = mid2.interfaceAddresses;
+      addresses.clear ();
+      addresses.push_back (Ipv4Address ("2.2.3.4"));
+      addresses.push_back (Ipv4Address ("2.2.3.5"));
     }
 
-  return result;
+    msg2.SetTimeToLive (254);
+    msg2.SetOriginatorAddress (Ipv4Address ("12.22.33.44"));
+    msg2.SetVTime (Seconds (10));
+    msg2.SetMessageType (olsr::MessageHeader::MID_MESSAGE);
+    msg2.SetMessageSequenceNumber (7);
+
+    // Build an OLSR packet header
+    hdr.SetPacketLength (hdr.GetSerializedSize () + msg1.GetSerializedSize () + msg2.GetSerializedSize ());
+    hdr.SetPacketSequenceNumber (123);
+    
+
+    // Now add all the headers in the correct order
+    packet.AddHeader (msg2);
+    packet.AddHeader (msg1);
+    packet.AddHeader (hdr);
+  }    
+
+  {
+    olsr::PacketHeader hdr;
+    packet.RemoveHeader (hdr);
+    NS_TEST_ASSERT_MSG_EQ (hdr.GetPacketSequenceNumber (), 123, "XXX");
+    uint32_t sizeLeft = hdr.GetPacketLength () - hdr.GetSerializedSize ();
+    {
+      olsr::MessageHeader msg1;
+      
+      packet.RemoveHeader (msg1);
+        
+      NS_TEST_ASSERT_MSG_EQ (msg1.GetTimeToLive (),  255, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg1.GetOriginatorAddress (), Ipv4Address ("11.22.33.44"), "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg1.GetVTime (), Seconds (9), "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg1.GetMessageSequenceNumber (), 7, "XXX");
+
+      olsr::MessageHeader::Mid &mid1 = msg1.GetMid ();
+      NS_TEST_ASSERT_MSG_EQ (mid1.interfaceAddresses.size (), 2, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (*mid1.interfaceAddresses.begin (), Ipv4Address ("1.2.3.4"), "XXX");
+
+      sizeLeft -= msg1.GetSerializedSize ();
+      NS_TEST_ASSERT_MSG_EQ((sizeLeft > 0), true, "XXX");
+    }
+    {
+      // now read the second message
+      olsr::MessageHeader msg2;
+
+      packet.RemoveHeader (msg2);
+        
+      NS_TEST_ASSERT_MSG_EQ (msg2.GetTimeToLive (),  254, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg2.GetOriginatorAddress (), Ipv4Address ("12.22.33.44"), "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg2.GetVTime (), Seconds (10), "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageType (), olsr::MessageHeader::MID_MESSAGE, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (msg2.GetMessageSequenceNumber (), 7, "XXX");
+
+      olsr::MessageHeader::Mid mid2 = msg2.GetMid ();
+      NS_TEST_ASSERT_MSG_EQ (mid2.interfaceAddresses.size (), 2, "XXX");
+      NS_TEST_ASSERT_MSG_EQ (*mid2.interfaceAddresses.begin (), Ipv4Address ("2.2.3.4"), "XXX");
+
+      sizeLeft -= msg2.GetSerializedSize ();
+      NS_TEST_ASSERT_MSG_EQ (sizeLeft, 0, "XXX");
+    }
+  }
+  return false;
 }
 
-static OlsrHeaderTest gOlsrHeaderTest;
+
+class OlsrHelloTestCase : public TestCase {
+public:
+  OlsrHelloTestCase ();
+  virtual bool DoRun (void);
+};
+
+OlsrHelloTestCase::OlsrHelloTestCase ()
+  : TestCase ("Check Hello olsr messages")
+{}
+bool 
+OlsrHelloTestCase::DoRun (void)
+{
+  Packet packet;
+  olsr::MessageHeader msgIn;
+  olsr::MessageHeader::Hello &helloIn = msgIn.GetHello ();
+
+  helloIn.SetHTime (Seconds (7));
+  helloIn.willingness = 66;
+
+  {
+    olsr::MessageHeader::Hello::LinkMessage lm1;
+    lm1.linkCode = 2;
+    lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.4"));
+    lm1.neighborInterfaceAddresses.push_back (Ipv4Address ("1.2.3.5"));
+    helloIn.linkMessages.push_back (lm1);
+    
+    olsr::MessageHeader::Hello::LinkMessage lm2;
+    lm2.linkCode = 3;
+    lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.4"));
+    lm2.neighborInterfaceAddresses.push_back (Ipv4Address ("2.2.3.5"));
+    helloIn.linkMessages.push_back (lm2);
+  }
+
+  packet.AddHeader (msgIn);
+
+  olsr::MessageHeader msgOut;
+  packet.RemoveHeader (msgOut);
+  olsr::MessageHeader::Hello &helloOut = msgOut.GetHello ();
+    
+  NS_TEST_ASSERT_MSG_EQ (helloOut.GetHTime (), Seconds (7), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.willingness, 66, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages.size (), 2, "XXX");
+  
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].linkCode, 2, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[0],
+                         Ipv4Address ("1.2.3.4"), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[0].neighborInterfaceAddresses[1],
+                         Ipv4Address ("1.2.3.5"), "XXX");
+
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].linkCode, 3, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[0],
+                         Ipv4Address ("2.2.3.4"), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (helloOut.linkMessages[1].neighborInterfaceAddresses[1],
+                         Ipv4Address ("2.2.3.5"), "XXX");
+
+  NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
+
+  return false;
+}
+
+class OlsrTcTestCase : public TestCase {
+public:
+  OlsrTcTestCase ();
+  virtual bool DoRun (void);
+};
 
-}; // namespace
+OlsrTcTestCase::OlsrTcTestCase ()
+  : TestCase ("Check Tc olsr messages")
+{}
+bool 
+OlsrTcTestCase::DoRun (void)
+{
+  Packet packet;
+  olsr::MessageHeader msgIn;
+  olsr::MessageHeader::Tc &tcIn = msgIn.GetTc ();
+  
+  tcIn.ansn = 0x1234;
+  tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.4"));
+  tcIn.neighborAddresses.push_back (Ipv4Address ("1.2.3.5"));
+  packet.AddHeader (msgIn);
+  
+  olsr::MessageHeader msgOut;
+  packet.RemoveHeader (msgOut);
+  olsr::MessageHeader::Tc &tcOut = msgOut.GetTc ();
+  
+  NS_TEST_ASSERT_MSG_EQ (tcOut.ansn, 0x1234, "XXX");
+  NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses.size (), 2, "XXX");
+  
+  NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[0],
+                         Ipv4Address ("1.2.3.4"), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (tcOut.neighborAddresses[1],
+                         Ipv4Address ("1.2.3.5"), "XXX");
+
+  NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "XXX");
+
+  return false;
+}
+
+class OlsrHnaTestCase : public TestCase {
+public:
+  OlsrHnaTestCase ();
+  virtual bool DoRun (void);
+};
+
+OlsrHnaTestCase::OlsrHnaTestCase ()
+  : TestCase ("Check Hna olsr messages")
+{}
+
+bool
+OlsrHnaTestCase::DoRun (void)
+{
+  Packet packet;
+  olsr::MessageHeader msgIn;
+  olsr::MessageHeader::Hna &hnaIn = msgIn.GetHna ();
+  
+  hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
+                                { Ipv4Address ("1.2.3.4"), Ipv4Mask ("255.255.255.0")});
+  hnaIn.associations.push_back ((olsr::MessageHeader::Hna::Association)
+                                {Ipv4Address ("1.2.3.5"), Ipv4Mask ("255.255.0.0")});
+  packet.AddHeader (msgIn);
+  
+  olsr::MessageHeader msgOut;
+  packet.RemoveHeader (msgOut);
+  olsr::MessageHeader::Hna &hnaOut = msgOut.GetHna ();
+  
+  NS_TEST_ASSERT_MSG_EQ (hnaOut.associations.size (), 2, "XXX");
+  
+  NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].address,
+                        Ipv4Address ("1.2.3.4"), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[0].mask,
+                        Ipv4Mask ("255.255.255.0"), "XXX");
+
+  NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].address,
+                        Ipv4Address ("1.2.3.5"), "XXX");
+  NS_TEST_ASSERT_MSG_EQ (hnaOut.associations[1].mask,
+                        Ipv4Mask ("255.255.0.0"), "XXX");
+  
+  NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read");
+
+  return false;
+}
 
 
-#endif /* RUN_SELF_TESTS */
+static class OlsrTestSuite : public TestSuite
+{
+public:
+  OlsrTestSuite ();
+} g_olsrTestSuite;
+
+OlsrTestSuite::OlsrTestSuite()
+  : TestSuite("olsr-routing", UNIT)
+{
+  AddTestCase(new OlsrHnaTestCase());
+  AddTestCase(new OlsrTcTestCase());
+  AddTestCase(new OlsrHelloTestCase());
+  AddTestCase(new OlsrMidTestCase());
+  AddTestCase(new OlsrEmfTestCase());
+}
+
+} // namespace ns3
+
--- a/src/simulator/default-simulator-impl.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/default-simulator-impl.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -268,6 +268,11 @@
 {
   if (ev.GetUid () == 2)
     {
+      if (ev.PeekEventImpl () == 0 ||
+          ev.PeekEventImpl ()->IsCancelled ())
+        {
+          return true;
+        }
       // destroy events.
       for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++)
         {
--- a/src/simulator/high-precision-128.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/high-precision-128.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -260,46 +260,31 @@
     }
 }
 
-}; // namespace ns3
+} // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
 #include "ns3/test.h"
 
-namespace ns3 {
-
-class HighPrecision128Tests : public Test
-{
-public:
-  HighPrecision128Tests ();
-  virtual ~HighPrecision128Tests ();
-  virtual bool RunTests (void);
-};
-
-HighPrecision128Tests::HighPrecision128Tests ()
-  : Test ("Int128")
-{}
-HighPrecision128Tests::~HighPrecision128Tests ()
-{}
-
-#define CHECK_EXPECTED(v,expected)                                      \
-  {                                                                     \
-    if (v.GetInteger () != expected)                                    \
-      {                                                                 \
-        Failure () << "file="<<__FILE__<<", line="<<__LINE__<<          \
-          ", expected: "<<expected<<", got: "<< v.GetInteger ()<<std::endl; \
-        result = false;                                                 \
-      }                                                                 \
-  }
+#define CHECK_EXPECTED(a,b) \
+  NS_TEST_ASSERT_MSG_EQ(a.GetInteger(),b,"Arithmetic failure: " << (a.GetInteger()) << "!=" << (b))
 
 #define V(v) \
   HighPrecision (v, false)
 
-bool
-HighPrecision128Tests::RunTests (void)
+namespace ns3 {
+
+class Hp128ArithmeticTestCase : public TestCase
 {
-  bool result = true;
+public:
+  Hp128ArithmeticTestCase ();
+  virtual bool DoRun (void);
+};
 
+Hp128ArithmeticTestCase::Hp128ArithmeticTestCase ()
+  : TestCase ("Check basic arithmetic operations")
+{}
+bool 
+Hp128ArithmeticTestCase::DoRun (void)
+{
   HighPrecision a, b;
   a = HighPrecision (1, false);
   b = HighPrecision (1, false);
@@ -406,34 +391,53 @@
   a.Div (V(3));
   a.Mul (V(3));
   CHECK_EXPECTED (a, 1999999999);
-  
-  // Bug 455
-  a = HighPrecision (0.1);
+
+  return false;
+}
+
+class Hp128Bug455TestCase : public TestCase
+{
+public:
+  Hp128Bug455TestCase();
+  virtual bool DoRun (void);
+};
+
+Hp128Bug455TestCase::Hp128Bug455TestCase()
+  : TestCase("Test case for bug 455")
+{}
+bool 
+Hp128Bug455TestCase::DoRun (void)
+{
+  HighPrecision a = HighPrecision (0.1);
   a.Div (HighPrecision (1.25));
-  NS_TEST_ASSERT_EQUAL (a.GetDouble (), 0.08);
-  //test the multiplication
+  NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 0.08, "The original testcase");
   a = HighPrecision (0.5);
   a.Mul(HighPrecision (5));
-  NS_TEST_ASSERT_EQUAL (a.GetDouble (), 2.5);
-  //test the sign of multiplication, first operand negative
+  NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 2.5, "Simple test for multiplication");
   a = HighPrecision (-0.5);
   a.Mul(HighPrecision (5));
-  NS_TEST_ASSERT_EQUAL (a.GetDouble (), -2.5);
-  //two negative
+  NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -2.5, "Test sign, first operation negative");
   a = HighPrecision (-0.5);
   a.Mul(HighPrecision (-5));
-  NS_TEST_ASSERT_EQUAL (a.GetDouble (), 2.5);
-  //second operand negative
+  NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 2.5, "both operands negative");
   a = HighPrecision (0.5);
   a.Mul(HighPrecision (-5));
-  NS_TEST_ASSERT_EQUAL (a.GetDouble (), -2.5);
+  NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -2.5, "only second operand negative");
+
+  return false;
+}
+
 
 
-  return result;
-}
-
-static HighPrecision128Tests g_int128Tests;
+static class HighPrecision128TestSuite : public TestSuite
+{
+public:
+  HighPrecision128TestSuite()
+    : TestSuite ("high-precision-128", UNIT)
+  {
+    AddTestCase (new Hp128ArithmeticTestCase());
+    AddTestCase (new Hp128Bug455TestCase());
+  }
+} g_highPrecision128TestSuite;
 
 } // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
--- a/src/simulator/realtime-simulator-impl.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/realtime-simulator-impl.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -725,6 +725,11 @@
 {
   if (ev.GetUid () == 2)
     {
+      if (ev.PeekEventImpl () == 0 ||
+          ev.PeekEventImpl ()->IsCancelled ())
+        {
+          return true;
+        }
       // destroy events.
       for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); 
            i != m_destroyEvents.end (); i++)
--- a/src/simulator/simulator.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/simulator.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -316,11 +316,7 @@
 
 } // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
-#include "ns3/ptr.h"
 #include "list-scheduler.h"
 #include "heap-scheduler.h"
 #include "map-scheduler.h"
@@ -329,6 +325,190 @@
 
 namespace ns3 {
 
+class SimulatorEventsTestCase : public TestCase
+{
+public:
+  SimulatorEventsTestCase (Ptr<Scheduler> scheduler);
+  virtual bool DoRun (void);
+  void A (int a);
+  void B (int b);
+  void C (int c);
+  void D (int d);
+  void foo0 (void);
+  uint64_t NowUs (void);
+  void destroy(void);
+  bool m_b;
+  bool m_a;
+  bool m_c;
+  bool m_d;
+  EventId m_idC;
+  bool m_destroy;
+  EventId m_destroyId;
+};
+
+SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr<Scheduler> scheduler)
+  : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ())
+{}
+uint64_t
+SimulatorEventsTestCase::NowUs (void)
+{
+  uint64_t ns = Now ().GetNanoSeconds ();
+  return ns / 1000;
+}  
+
+void
+SimulatorEventsTestCase::A (int a)
+{
+  m_a = false;
+}
+
+void
+SimulatorEventsTestCase::B (int b)
+{
+  if (b != 2 || NowUs () != 11) 
+    {
+      m_b = false;
+    } 
+  else 
+    {
+      m_b = true;
+    }
+  Simulator::Remove (m_idC);
+  Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D, this, 4);
+}
+
+void
+SimulatorEventsTestCase::C (int c)
+{
+  m_c = false;
+}
+
+void
+SimulatorEventsTestCase::D (int d)
+{
+  if (d != 4 || NowUs () != (11+10)) 
+    {
+      m_d = false;
+    } 
+  else 
+    {
+      m_d = true;
+    }
+}
+
+void
+SimulatorEventsTestCase::foo0(void)
+{}
+
+void
+SimulatorEventsTestCase::destroy (void)
+{
+  if (m_destroyId.IsExpired ())
+    {
+      m_destroy = true; 
+    }
+}
+bool 
+SimulatorEventsTestCase::DoRun (void)
+{
+  m_a = true;
+  m_b = false;
+  m_c = true;
+  m_d = false;
+
+  EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
+  Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
+  m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
+
+  NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, "");
+  NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, "");
+  Simulator::Cancel (a);
+  NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, "");
+  Simulator::Run ();
+  NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?");
+  NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?");
+  NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?");
+  NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?");
+
+  EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::foo0, this);
+  EventId anotherId = anId;
+  NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet.");
+
+  Simulator::Remove (anId);
+  NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired");
+  NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired");
+
+  m_destroy = false;
+  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
+  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
+  m_destroyId.Cancel ();
+  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
+
+  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
+  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
+  Simulator::Remove (m_destroyId);
+  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now");
+
+  m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this);
+  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
+
+  Simulator::Run ();
+  NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet");
+  NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run");
+
+  Simulator::Destroy ();
+  NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now");
+  NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run");
+
+  return false;
+}
+
+class SimulatorTemplateTestCase : public TestCase
+{
+public:
+  SimulatorTemplateTestCase ();
+  // only here for testing of Ptr<>
+  void Ref (void) const {}
+  void Unref (void) const {}
+private:
+  virtual bool DoRun (void);
+
+  void bar0 (void) {}
+  void bar1 (int) {}
+  void bar2 (int, int) {}
+  void bar3 (int, int, int) {}
+  void bar4 (int, int, int, int) {}
+  void bar5 (int, int, int, int, int) {}
+  void baz1 (int &) {}
+  void baz2 (int &, int &) {}
+  void baz3 (int &, int &, int &) {}
+  void baz4 (int &, int &, int &, int &) {}
+  void baz5 (int &, int &, int &, int &, int &) {}
+  void cbaz1 (const int &) {}
+  void cbaz2 (const int &, const int &) {}
+  void cbaz3 (const int &, const int &, const int &) {}
+  void cbaz4 (const int &, const int &, const int &, const int &) {}
+  void cbaz5 (const int &, const int &, const int &, const int &, const int &) {}
+
+  void bar0c (void) const {}
+  void bar1c (int) const {}
+  void bar2c (int, int) const {}
+  void bar3c (int, int, int) const {}
+  void bar4c (int, int, int, int) const {}
+  void bar5c (int, int, int, int, int) const {}
+  void baz1c (int &) const {}
+  void baz2c (int &, int &) const {}
+  void baz3c (int &, int &, int &) const {}
+  void baz4c (int &, int &, int &, int &) const {}
+  void baz5c (int &, int &, int &, int &, int &) const {}
+  void cbaz1c (const int &) const {}
+  void cbaz2c (const int &, const int &) const {}
+  void cbaz3c (const int &, const int &, const int &) const {}
+  void cbaz4c (const int &, const int &, const int &, const int &) const {}
+  void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {}
+
+};
+
 static void foo0 (void)
 {}
 static void foo1 (int)
@@ -341,8 +521,6 @@
 {}
 static void foo5 (int, int, int, int, int)
 {}
-
-#if 1
 static void ber1 (int &)
 {}
 static void ber2 (int &, int &)
@@ -353,8 +531,6 @@
 {}
 static void ber5 (int &, int &, int &, int &, int &)
 {}
-#endif
-
 static void cber1 (const int &)
 {}
 static void cber2 (const int &, const int &)
@@ -365,407 +541,85 @@
 {}
 static void cber5 (const int &, const int &, const int &, const int &, const int &)
 {}
-  
-
-class SimulatorTests : public Test
-{
-public:
-  SimulatorTests ();
-  // only here for testing of Ptr<>
-  void Ref (void) const;
-  void Unref (void) const;
-  virtual ~SimulatorTests ();
-  virtual bool RunTests (void);
-private:
-  uint64_t NowUs ();
-  bool RunOneTest (void);
-  void RunTestsConst (void) const;
-  void A (int a);
-  void B (int b);
-  void C (int c);
-  void D (int d);
-  void bar0 (void);
-  void bar1 (int);
-  void bar2 (int, int);
-  void bar3 (int, int, int);
-  void bar4 (int, int, int, int);
-  void bar5 (int, int, int, int, int);
-  void baz1 (int &);
-  void baz2 (int &, int &);
-  void baz3 (int &, int &, int &);
-  void baz4 (int &, int &, int &, int &);
-  void baz5 (int &, int &, int &, int &, int &);
-  void cbaz1 (const int &);
-  void cbaz2 (const int &, const int &);
-  void cbaz3 (const int &, const int &, const int &);
-  void cbaz4 (const int &, const int &, const int &, const int &);
-  void cbaz5 (const int &, const int &, const int &, const int &, const int &);
-
-  void bar0c (void) const;
-  void bar1c (int) const;
-  void bar2c (int, int) const;
-  void bar3c (int, int, int) const;
-  void bar4c (int, int, int, int) const;
-  void bar5c (int, int, int, int, int) const;
-  void baz1c (int &) const;
-  void baz2c (int &, int &) const;
-  void baz3c (int &, int &, int &) const;
-  void baz4c (int &, int &, int &, int &) const;
-  void baz5c (int &, int &, int &, int &, int &) const;
-  void cbaz1c (const int &) const;
-  void cbaz2c (const int &, const int &) const;
-  void cbaz3c (const int &, const int &, const int &) const;
-  void cbaz4c (const int &, const int &, const int &, const int &) const;
-  void cbaz5c (const int &, const int &, const int &, const int &, const int &) const;
-
-  void destroy (void);
-  
-  bool m_b;
-  bool m_a;
-  bool m_c;
-  bool m_d;
-  EventId m_idC;
-  bool m_destroy;
-  EventId m_destroyId;
-};
-
-SimulatorTests::SimulatorTests ()
-  : Test ("Simulator")
-{}
-
-SimulatorTests::~SimulatorTests ()
-{}
-
-void 
-SimulatorTests::Ref (void) const
-{}
-
-void 
-SimulatorTests::Unref (void) const
-{}
-
-uint64_t
-SimulatorTests::NowUs (void)
-{
-  uint64_t ns = Now ().GetNanoSeconds ();
-  return ns / 1000;
-}  
-
-void
-SimulatorTests::A (int a)
-{
-  m_a = false;
-}
-
-void
-SimulatorTests::B (int b)
-{
-  if (b != 2 || NowUs () != 11) 
-    {
-      m_b = false;
-    } 
-  else 
-    {
-      m_b = true;
-    }
-  Simulator::Remove (m_idC);
-  Simulator::Schedule (MicroSeconds (10), &SimulatorTests::D, this, 4);
-}
-
-void
-SimulatorTests::C (int c)
-{
-  m_c = false;
-}
-
-void
-SimulatorTests::D (int d)
-{
-  if (d != 4 || NowUs () != (11+10)) 
-    {
-      m_d = false;
-    } 
-  else 
-    {
-      m_d = true;
-    }
-}
-
-void
-SimulatorTests::destroy (void)
-{
-  if (m_destroyId.IsExpired ())
-    {
-      m_destroy = true; 
-    }
-}
-
-void 
-SimulatorTests::bar0 (void)
-{}
-
-void 
-SimulatorTests::bar1 (int)
-{}
-
-void 
-SimulatorTests::bar2 (int, int)
-{}
-
-void 
-SimulatorTests::bar3 (int, int, int)
-{}
-
-void 
-SimulatorTests::bar4 (int, int, int, int)
-{}
-
-void 
-SimulatorTests::bar5 (int, int, int, int, int)
-{}
-
-void
-SimulatorTests::baz1 (int &)
-{}
-
-void
-SimulatorTests::baz2 (int &, int &)
-{}
-
-void
-SimulatorTests::baz3 (int &, int &, int &)
-{}
-
-void 
-SimulatorTests::baz4 (int &, int &, int &, int &)
-{}
-
-void 
-SimulatorTests::baz5 (int &, int &, int &, int &, int &)
-{}
-
-void
-SimulatorTests::cbaz1 (const int &)
-{}
-
-void
-SimulatorTests::cbaz2 (const int &, const int &)
-{}
-
-void
-SimulatorTests::cbaz3 (const int &, const int &, const int &)
-{}
-
-void 
-SimulatorTests::cbaz4 (const int &, const int &, const int &, const int &)
-{}
-
-void 
-SimulatorTests::cbaz5 (const int &, const int &, const int &, const int &, const int &)
-{}
 
-void 
-SimulatorTests::bar0c (void) const
-{}
-
-void 
-SimulatorTests::bar1c (int) const
-{}
-
-void 
-SimulatorTests::bar2c (int, int) const
-{}
-
-void 
-SimulatorTests::bar3c (int, int, int) const
-{}
-
-void 
-SimulatorTests::bar4c (int, int, int, int) const
-{}
-
-void 
-SimulatorTests::bar5c (int, int, int, int, int) const
-{}
-
-void
-SimulatorTests::baz1c (int &) const
-{}
-
-void
-SimulatorTests::baz2c (int &, int &) const
-{}
-
-void
-SimulatorTests::baz3c (int &, int &, int &) const
-{}
-
-void 
-SimulatorTests::baz4c (int &, int &, int &, int &) const
-{}
-
-void 
-SimulatorTests::baz5c (int &, int &, int &, int &, int &) const
+SimulatorTemplateTestCase::SimulatorTemplateTestCase ()
+  : TestCase ("Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.")
 {}
-
-void
-SimulatorTests::cbaz1c (const int &) const
-{}
-
-void
-SimulatorTests::cbaz2c (const int &, const int &) const
-{}
-
-void
-SimulatorTests::cbaz3c (const int &, const int &, const int &) const
-{}
-
-void 
-SimulatorTests::cbaz4c (const int &, const int &, const int &, const int &) const
-{}
-
-void 
-SimulatorTests::cbaz5c (const int &, const int &, const int &, const int &, const int &) const
-{}
-
-bool
-SimulatorTests::RunOneTest (void)
-{
-  bool result = true;
-  m_a = true;
-  m_b = false;
-  m_c = true;
-  m_d = false;
-
-  EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorTests::A, this, 1);
-  Simulator::Schedule (MicroSeconds (11), &SimulatorTests::B, this, 2);
-  m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorTests::C, this, 3);
-
-  NS_TEST_ASSERT (!m_idC.IsExpired ());
-  NS_TEST_ASSERT (!a.IsExpired ());
-  Simulator::Cancel (a);
-  NS_TEST_ASSERT (a.IsExpired ());
-  Simulator::Run ();
-  NS_TEST_ASSERT (m_a);
-  NS_TEST_ASSERT (m_b);
-  NS_TEST_ASSERT (m_c);
-  NS_TEST_ASSERT (m_d);
-  return result;
-}
-
-void
-SimulatorTests::RunTestsConst (void) const
+bool 
+SimulatorTemplateTestCase::DoRun (void)
 {
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, this);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1c, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2c, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3c, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar0c, this);
-  Simulator::ScheduleNow (&SimulatorTests::bar1c, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar2c, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar3c, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz1c, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz2c, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz3c, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
-  Simulator::ScheduleNow (&SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar0c, this);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar1c, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar2c, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar3c, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz1c, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz2c, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz3c, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar0c, Ptr<const SimulatorTests> (this));
-  Simulator::ScheduleDestroy (&SimulatorTests::bar1c, Ptr<const SimulatorTests> (this), 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar2c, Ptr<const SimulatorTests> (this), 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar3c, Ptr<const SimulatorTests> (this), 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar4c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar5c, Ptr<const SimulatorTests> (this), 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1c, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2c, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3c, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4c, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz1c, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz2c, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz3c, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz1c, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz2c, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz3c, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz4c, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0);
+  // Test schedule of const methods
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0);
 
-  Simulator::Run ();
-  Simulator::Destroy ();
-}
-
-bool 
-SimulatorTests::RunTests (void)
-{
-  bool result = true;
+  // Test of schedule const methods with Ptr<> pointers
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr<const SimulatorTemplateTestCase> (this));
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr<const SimulatorTemplateTestCase> (this), 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr<const SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
 
-  Simulator::Destroy ();
-  Simulator::SetScheduler (CreateObject<ListScheduler> ());
-  if (!RunOneTest ()) 
-    {
-      result = false;
-    }
-  Simulator::Destroy ();
-  Simulator::SetScheduler (CreateObject<HeapScheduler> ());
-  if (!RunOneTest ()) 
-    {
-      result = false;
-    }
-  Simulator::Destroy ();
-  Simulator::SetScheduler (CreateObject<MapScheduler> ());
-  if (!RunOneTest ()) 
-    {
-      result = false;
-    }
-  Simulator::Destroy ();
 
-  Simulator::SetScheduler (CreateObject<CalendarScheduler> ());
-  if (!RunOneTest ()) 
-    {
-      result = false;
-    }
-  Simulator::Destroy ();
-
-  Simulator::SetScheduler (CreateObject<Ns2CalendarScheduler> ());
-  if (!RunOneTest ()) 
-    {
-      result = false;
-    }
-  Simulator::Destroy ();
-
+  // Test schedule of raw functions
   Simulator::Schedule (Seconds (0.0), &foo0);
   Simulator::Schedule (Seconds (0.0), &foo1, 0);
   Simulator::Schedule (Seconds (0.0), &foo2, 0, 0);
@@ -777,23 +631,6 @@
   Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0);
   Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0);
   Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, Ptr<SimulatorTests> (this));
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
   Simulator::ScheduleNow (&foo0);
   Simulator::ScheduleNow (&foo1, 0);
   Simulator::ScheduleNow (&foo2, 0, 0);
@@ -805,23 +642,6 @@
   Simulator::ScheduleNow (&cber3, 0, 0, 0);
   Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
   Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar0, this);
-  Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz1, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz2, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz3, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz4, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar0, Ptr<SimulatorTests> (this));
-  Simulator::ScheduleNow (&SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
   Simulator::ScheduleDestroy (&foo0);
   Simulator::ScheduleDestroy (&foo1, 0);
   Simulator::ScheduleDestroy (&foo2, 0, 0);
@@ -833,96 +653,120 @@
   Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
   Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
   Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar0, this);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz1, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz2, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz3, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz4, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar0, Ptr<SimulatorTests> (this));
-  Simulator::ScheduleDestroy (&SimulatorTests::bar1, Ptr<SimulatorTests> (this), 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar2, Ptr<SimulatorTests> (this), 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar3, Ptr<SimulatorTests> (this), 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar4, Ptr<SimulatorTests> (this), 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::bar5, Ptr<SimulatorTests> (this), 0, 0, 0, 0, 0);
+
+
+  // Test schedule of normal member methods
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0);
+
+
+  // test schedule of normal methods with Ptr<> pointers
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr<SimulatorTemplateTestCase> (this));
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr<SimulatorTemplateTestCase> (this), 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr<SimulatorTemplateTestCase> (this), 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr<SimulatorTemplateTestCase> (this), 0, 0, 0, 0, 0);
 
 
   // the code below does not compile, as expected.
   //Simulator::Schedule (Seconds (0.0), &cber1, 0.0);
 
-#if 1
+
+  // This code appears to be duplicate test code.
   Simulator::Schedule (Seconds (0.0), &ber1, 0);
   Simulator::Schedule (Seconds (0.0), &ber2, 0, 0);
   Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0);
   Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0);
   Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1, this, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2, this, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3, this, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4, this, 0, 0, 0, 0);
-  Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
+  Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
   Simulator::ScheduleNow (&ber1, 0);
   Simulator::ScheduleNow (&ber2, 0, 0);
   Simulator::ScheduleNow (&ber3, 0, 0, 0);
   Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
   Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz1, this, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz2, this, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz3, this, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz4, this, 0, 0, 0, 0);
-  Simulator::ScheduleNow (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
+  Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
   Simulator::ScheduleDestroy (&ber1, 0);
   Simulator::ScheduleDestroy (&ber2, 0, 0);
   Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
   Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
   Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz1, this, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz2, this, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz3, this, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz4, this, 0, 0, 0, 0);
-  Simulator::ScheduleDestroy (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0);
-#endif
-
-  RunTestsConst ();
-
-  EventId nowId = Simulator::ScheduleNow (&foo0);
-  m_destroyId = Simulator::ScheduleDestroy (&SimulatorTests::destroy, this);
-  NS_TEST_ASSERT (!m_destroyId.IsExpired ());
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0);
+  Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0);
 
-  Simulator::Run ();
-  m_destroy = false;
-  Simulator::Destroy ();
-  NS_TEST_ASSERT (m_destroy);
-
-  EventId anId = Simulator::ScheduleNow (&foo0);
-  EventId anotherId = anId;
-  NS_TEST_ASSERT (!(anId.IsExpired () || anotherId.IsExpired ()));
-
-  Simulator::Remove (anId);
-  NS_TEST_ASSERT (anId.IsExpired ());
-  NS_TEST_ASSERT (anotherId.IsExpired ());
 
   Simulator::Run ();
   Simulator::Destroy ();
 
-  Simulator::Schedule (Seconds (10.0), &SimulatorTests::baz1, this, 0);
-  Simulator::Stop (Seconds (1.0));
-  Simulator::Run ();
-  Simulator::Destroy ();
-
-  return result;
+  return false;
 }
 
-SimulatorTests gSimulatorTests;
-
-}; // namespace ns3
+class SimulatorTestSuite : public TestSuite
+{
+public:
+  SimulatorTestSuite ()
+    : TestSuite ("simulator")
+  {
+    AddTestCase (new SimulatorEventsTestCase (CreateObject<ListScheduler> ()));
+    AddTestCase (new SimulatorEventsTestCase (CreateObject<MapScheduler> ()));
+    AddTestCase (new SimulatorEventsTestCase (CreateObject<HeapScheduler> ()));
+    AddTestCase (new SimulatorEventsTestCase (CreateObject<CalendarScheduler> ()));
+    AddTestCase (new SimulatorEventsTestCase (CreateObject<Ns2CalendarScheduler> ()));
+  }
+} g_simulatorTestSuite;
 
-#endif /* RUN_SELF_TESTS */
-
-
-
+} // namespace ns3
--- a/src/simulator/time.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/time.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -361,501 +361,336 @@
 
 } // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
-//#include <iostream>
 
 namespace ns3 {
 
-class TimeTests : public Test
+#define PRECISION(mult) (pow(10,-((double)(ns3::TimeStepPrecision::Get ())))*mult)
+#define ASSERT_MSG_EQ(a,b,mult,msg)                                     \
+  NS_TEST_ASSERT_MSG_EQ(((a)<((b)-PRECISION(mult)) || (a)>((b)+PRECISION(mult))),false, \
+                        msg << " Values are not equal within requested precision range: " << \
+                        (a) << "!=" << (b) << " ~ " << PRECISION(mult))
+#define ASSERT_MSG_EQ_INT(a,b,mult,msg) \
+  ASSERT_MSG_EQ(((int64_t)(a)),((int64_t)(b)),mult,msg)
+#define ASSERT_EQ(a,b)                          \
+  ASSERT_MSG_EQ(a,b,1,"")
+
+class OldTimeTestCase : public TestCase
 {
 public:
-  TimeTests ();
-  virtual ~TimeTests ();
-  virtual bool RunTests (void);
-
-  /*
-   * Verifies that a calculated time value is as expected using
-   * doubles since GetSeconds() returns a double
-   */ 
-  void CheckTimeSec(std::string test_id, double actual, double expected, 
-                    bool *flag, double precMultFactor = 1, 
-                    bool verbose = false);
-
-  /*
-   * Verifies that a calculated time value is as expected.
-   */ 
-  void CheckTime(std::string test_id, int64_t actual, int64_t expected, 
-                 bool *flag, double precMultFactor = 1, 
-                 bool verbose = false);
-
-  /*
-   * Verifies the +, -, * and / operations for the TimeUnit<1> or Time class
-   */
-  void CheckOperations(Time t0, Time t1, bool *ok, bool verbose = false);
-
-  /*
-   * Verifies that the TimeUnit class stores values with the precision
-   * set in the variable TimeStepPrecision::Get
-   * Checks that overflow and underflow occur at expected numbers
-   */
-  void CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok,
-                      bool verbose = false);
-
-  /*
-   * Verifies that the conversion between units in the class
-   * TimeUnit<1> or Time is done correctly. This is verified both when
-   * setting and retrieving a Time value
-   */
-  void CheckConversions(uint64_t tval, bool *ok, bool verbose = false);
-
-  /*
-   * These are the old tests that used to be run
-   */
-  void CheckOld(bool *ok);
+  OldTimeTestCase();
+  virtual bool DoRun (void);
 };
 
-TimeTests::TimeTests ()
-  : Test ("Time")
+OldTimeTestCase::OldTimeTestCase()
+  : TestCase("Sanity check of common time operations")
 {}
-TimeTests::~TimeTests ()
-{}
+bool 
+OldTimeTestCase::DoRun (void)
+{  
+  NS_TEST_ASSERT_MSG_EQ(TimeStepPrecision::Get(), 
+                        TimeStepPrecision::NS,
+                        "Invalid precision mode");
 
-bool TimeTests::RunTests (void)
-{
-  bool result = true;
+  Time t0 = Seconds (10.0);
+  ASSERT_EQ(t0.GetSeconds(), 10.0);
+
+  Time t1 = Seconds (11.0);
+  ASSERT_EQ(t1.GetSeconds(), 11.0);
 
-  Time t0, t1;
+  t0 = Seconds (1.5);
+  ASSERT_EQ(t0.GetSeconds(), 1.5);
 
-  CheckOld(&result);
+  t0 = Seconds (-1.5);
+  ASSERT_EQ(t0.GetSeconds(), -1.5);
 
   t0 = MilliSeconds ((uint64_t)10.0);
-  t1 = MilliSeconds ((uint64_t)11.0);
-
-  CheckOperations(t0, t1, &result);
-
-  //  t0 = Seconds ((uint64_t)10.0);
-  //  t1 = Seconds ((uint64_t)11.0);
-
-  //  CheckOperations(t0, t1, &result);
-
-  CheckConversions((uint64_t)5, &result);
-  CheckConversions((uint64_t)0, &result);
-  CheckConversions((uint64_t)783, &result);
-  CheckConversions((uint64_t)1132, &result);
-  //  CheckConversions((uint64_t)3341039, &result);
-
-  // Now vary the precision and check the conversions
-  if (TimeStepPrecision::Get () != TimeStepPrecision::NS) {
-    result = false;
-  }
-
-  CheckPrecision(TimeStepPrecision::US, 7, &result);
-
-  CheckConversions((uint64_t)7, &result);
-  CheckConversions((uint64_t)546, &result);
-  CheckConversions((uint64_t)6231, &result);
-  //  CheckConversions((uint64_t)1234639, &result);
-
-  CheckPrecision(TimeStepPrecision::MS, 3, &result);
-
-  CheckConversions((uint64_t)3, &result);
-  CheckConversions((uint64_t)134, &result);
-  CheckConversions((uint64_t)2341, &result);
-  //  CheckConversions((uint64_t)8956239, &result);
-
-  CheckPrecision(TimeStepPrecision::PS, 21, &result);
-
-  CheckConversions((uint64_t)4, &result);
-  CheckConversions((uint64_t)342, &result);
-  CheckConversions((uint64_t)1327, &result);
-  //  CheckConversions((uint64_t)5439627, &result);
-
-  CheckPrecision(TimeStepPrecision::NS, 12, &result);
-  CheckConversions((uint64_t)12, &result);
-
-  CheckPrecision(TimeStepPrecision::S, 7, &result);
-  CheckConversions((uint64_t)7, &result);
-
-  CheckPrecision(TimeStepPrecision::FS, 5, &result);
-  CheckConversions((uint64_t)5, &result);
-
-  TimeStepPrecision::Set (TimeStepPrecision::NS);
-
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("S"));
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("MS"));
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("US"));
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("NS"));
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("PS"));
-  Config::SetGlobal ("TimeStepPrecision", StringValue ("FS"));
-
-
-  Time tooBig = TimeStep (0x8000000000000000LL);
-  NS_TEST_ASSERT (tooBig.IsNegative ());
-  tooBig = TimeStep (0xffffffffffffffffLL);
-  NS_TEST_ASSERT (tooBig.IsNegative ());
-  tooBig = TimeStep (0x7fffffffffffffffLL);
-  NS_TEST_ASSERT (tooBig.IsPositive ());
-  tooBig += TimeStep (1);
-  NS_TEST_ASSERT (tooBig.IsNegative ());
-
-  return result;
-}
-
-void TimeTests::CheckOld (bool *ok)
-{
-  double dt0, dt1, dt2;
-  int64_t it0, it1;
-
-  Time t0 = Seconds (10.0);
-  CheckTimeSec("old 1", t0.GetSeconds(), 10.0, ok);
-
-  Time t1 = Seconds (11.0);
-  CheckTimeSec("old 2", t1.GetSeconds(), 11.0, ok);
-
-  t0 = Seconds (1.5);
-  CheckTimeSec("old 3", t0.GetSeconds(), 1.5, ok);
-
-  t0 = Seconds (-1.5);
-  CheckTimeSec("old 4", t0.GetSeconds(), -1.5, ok);
-
-  t0 = MilliSeconds ((uint64_t)10.0);
-  dt0 = t0.GetSeconds();
-  CheckTimeSec("old 5", dt0, 0.01, ok);
+  ASSERT_EQ(t0.GetSeconds(), 0.01);
 
   t1 = MilliSeconds ((uint64_t)11.0);
-  dt1 = t1.GetSeconds();
-  CheckTimeSec("old 6", dt1, 0.011, ok);
+  ASSERT_EQ(t1.GetSeconds(), 0.011);
+
 
   Time t2, t3;
 
   t2 = t1 - t0;
-  if (!t2.IsStrictlyPositive ())
-    {
-      ok = false;
-    }
-  dt2 = t2.GetSeconds();
-  CheckTimeSec("old 7", dt2, dt1-dt0, ok);
+  NS_TEST_ASSERT_MSG_EQ(t2.IsStrictlyPositive (),true, "Variable should be positive");
+  ASSERT_EQ(t2.GetSeconds(), t1.GetSeconds()-t0.GetSeconds());
 
   t2 = t1 - t1;
-  if (!t2.IsZero ())
-    {
-      ok = false;
-    }
-  dt2 = t2.GetSeconds();
-  CheckTimeSec("old 8", dt2, dt1-dt1, ok);
-
-  t2 = t0 - t1;
-  if (!t2.IsStrictlyNegative ())
-    {
-      ok = false;
-    }
-  dt2 = t2.GetSeconds();
-  CheckTimeSec("old 9", dt2, dt0-dt1, ok);
-
-  t1 = NanoSeconds(15);
-  it0 = t0.GetNanoSeconds();
-  it1 = t1.GetNanoSeconds();
-  TimeUnit<-2> tu4 = t0 / (t1 * t1 * t1);
-  CheckTime("old 10", tu4.GetHighPrecision().GetInteger(), it0 / (it1*it1*it1), 
-            ok, 1e9);
-
-  Time tmp = MilliSeconds (0);
-  if ((tmp != NanoSeconds (0)) ||
-      (tmp > NanoSeconds (0)) ||
-      (tmp < NanoSeconds (0)))
-    {
-      ok = false;
-    }
-
-  Time t4;
-  t4 = Seconds (10.0) * Scalar (1.5);
-  CheckTimeSec("old 11", t4.GetSeconds(), 15, ok);
-
-  Time t5;
-  t5 = NanoSeconds (10) * Scalar (1.5);
-  CheckTime("old 12", t5.GetNanoSeconds(), 15, ok);
-
-  t4 = Seconds (10.0) * Scalar (15) / Scalar (10);
-  CheckTimeSec("old 13", t4.GetSeconds(), 15, ok);
-
-  t5 = NanoSeconds (10) * Scalar (15) / Scalar (10);
-  CheckTime("old 14", t5.GetNanoSeconds(), 15, ok);
-
-
-  double foo = (t1 + t2).GetSeconds ();
-  dt1 = t1.GetSeconds();
-  dt2 = t2.GetSeconds();
-  CheckTimeSec("old 15", foo, dt1+dt2, ok);
-
-  foo += (t4 == t5)? 1 : 0;
-  CheckTimeSec("old 16", foo, dt1+dt2, ok);
-
-  foo = (t1/t2).GetDouble ();
-  CheckTimeSec("old 17", foo, dt1/dt2, ok);
-}
-
-
-void TimeTests::CheckOperations(Time t0, Time t1, bool *ok, bool verbose) 
-{
-
-  if (verbose) 
-    std::cout << std::endl << "Check operations: " 
-              << t0 << " " << t1 << std::endl;
-
-  Time t2, t3;
-  double it0, it1, it2, it3, itu2, itu3;
-  int64_t iti0;
-
-  it0 = t0.GetSeconds();
-  it1 = t1.GetSeconds();
+  NS_TEST_ASSERT_MSG_EQ(t2.IsZero (),true, "Variable should be zero");
+  ASSERT_EQ(t2.GetSeconds(), t1.GetSeconds()-t1.GetSeconds());
 
   t2 = t0 - t1;
-  it2 = t2.GetSeconds();
-  CheckTimeSec("ops 1", it2, it0-it1, ok);
+  NS_TEST_ASSERT_MSG_EQ(t2.IsStrictlyNegative (),true, "Variable should be negative");
+  ASSERT_EQ(t2.GetSeconds(), t0.GetSeconds()-t1.GetSeconds());
 
-  t3 = t2 * t0 / t0;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 2a", it3, it2*it0/it0, ok);
+  Time tmp = MilliSeconds (0);
+  NS_TEST_ASSERT_MSG_EQ((MilliSeconds (0) == NanoSeconds(0)), true, "Zero is not Zero ?");
+  NS_TEST_ASSERT_MSG_EQ((MilliSeconds (0) > NanoSeconds(0)), false, "Zero is bigger than Zero ?");
+  NS_TEST_ASSERT_MSG_EQ((MilliSeconds (0) < NanoSeconds(0)), false, "Zero is smaller than Zero ?");
+
+  Time t4 = Seconds (10.0) * Scalar (1.5);
+  ASSERT_EQ(t4.GetSeconds(), 15.0);
 
-  t3 = t2 * t0 / t1;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 2", it3, it2*it0/it1, ok);
+  Time t5 = NanoSeconds (10) * Scalar (1.5);
+  ASSERT_EQ(t5.GetNanoSeconds(), 15.0);
+
+  Time t6 = Seconds (10.0) * Scalar (15) / Scalar (10);
+  ASSERT_EQ(t6.GetSeconds (), 15.0);
 
-  t3 = t0 * t2 / t1;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 3", it3, it0*it2/it1, ok);
+  Time t7 = NanoSeconds (10) * Scalar (15) / Scalar (10);
+  ASSERT_EQ(t7.GetNanoSeconds (), 15.0);
 
-  t3 = t0 * t1 / t2;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 4", it3, it0*it1/it2, ok);
+  ASSERT_EQ((t1 + t2).GetSeconds (), t1.GetSeconds()+t2.GetSeconds());
+
+  ASSERT_EQ((t1 / t2).GetDouble (), t1.GetSeconds()/t2.GetSeconds());
 
-  t3 = t0 * (t1 / t2);
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 5", it3, it0*(it1/it2), ok);
+  return false;
+}
 
-  t3 = (t0 * t1) / t2;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 6", it3, (it0*it1)/it2, ok);
+class OperationsTimeTestCase : public TestCase
+{
+public:
+  OperationsTimeTestCase();
+  virtual bool DoRun(void);
+};
 
-  t3 = t0 / t1 * t2;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 7", it3, it0/it1*it2, ok);
+OperationsTimeTestCase::OperationsTimeTestCase()
+  : TestCase ("Check the +, -, * and / operators for the TimeUnit<1>")
+{}
 
-  t3 = (t0 / t1) * t2;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 8", it3, (it0/it1)*it2, ok);
+bool
+OperationsTimeTestCase::DoRun(void)
+{
+  // What happens if you set these values ?
+  //  t0 = Seconds ((uint64_t)10.0);
+  //  t1 = Seconds ((uint64_t)11.0);
 
-  t3 = t0 * Scalar (10.0);
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 9", it3, it0*10, ok);
+  Time t0 = MilliSeconds(10);
+  Time t1 = MilliSeconds(11);
 
-  t3 = Scalar (10.0) * t0;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 10", it3, 10 * it0, ok);
-
-  t3 = Scalar (10.0) * t0 / t2 * t1;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 11", it3, 10 * it0 / it2 * it1, ok);
+  ASSERT_EQ((t0-t1).GetSeconds(),
+            (t0.GetSeconds()-t1.GetSeconds()));
+  ASSERT_EQ(((t0-t1) * t0 / t0).GetSeconds(),
+            ((t0.GetSeconds()-t1.GetSeconds()) * t0.GetSeconds () / t0.GetSeconds ()));
+  ASSERT_EQ(((t0-t1) * t0 / t1).GetSeconds(),
+            ((t0.GetSeconds()-t1.GetSeconds()) * t0.GetSeconds () / t1.GetSeconds ()));
+  ASSERT_EQ((t0 * (t0-t1) / t1).GetSeconds(),
+            (t0.GetSeconds () * (t0.GetSeconds()-t1.GetSeconds()) / t1.GetSeconds ()));
+  ASSERT_EQ((t0 * t1 / (t0-t1)).GetSeconds(),
+            (t0.GetSeconds () * t1.GetSeconds() / (t0.GetSeconds()-t1.GetSeconds())));
+  ASSERT_EQ((t0 * (t1 / (t0-t1))).GetSeconds(),
+            (t0.GetSeconds () * (t1.GetSeconds() / (t0.GetSeconds()-t1.GetSeconds()))));
+  ASSERT_EQ(((t0 * t1) / (t0-t1)).GetSeconds(),
+            ((t0.GetSeconds () * t1.GetSeconds()) / (t0.GetSeconds()-t1.GetSeconds())));
+  ASSERT_EQ((t0 / t1 * (t0-t1)).GetSeconds(),
+            (t0.GetSeconds () / t1.GetSeconds() * (t0.GetSeconds()-t1.GetSeconds())));
+  ASSERT_EQ(((t0 / t1) * (t0-t1)).GetSeconds(),
+              (t0.GetSeconds () / t1.GetSeconds()) * (t0.GetSeconds()-t1.GetSeconds()));
+  ASSERT_EQ((t0 * Scalar(10.0)).GetSeconds (), (t0.GetSeconds () * 10.0));
+  ASSERT_EQ((Scalar(10.0) * t0).GetSeconds (), (10.0 * t0.GetSeconds ()));
 
-  t3 = (Scalar (10.0) * t0 ) / t2 * t1;
-  it3 = t3.GetSeconds();
-  CheckTimeSec("ops 12", it3, (10 * it0) / it2 * it1, ok);
+  // Note: we need to multiply by 1e9 because GetSeconds is multiplying
+  ASSERT_EQ(((t0/(t1*(t0-t1))).GetHighPrecision().GetDouble() * 1e9),
+             (t0.GetSeconds()/(t1.GetSeconds()*(t0.GetSeconds()-t1.GetSeconds()))));
+
+  ASSERT_EQ((t0/t1).GetDouble(),(t0.GetSeconds()/t1.GetSeconds()));
+
 
-  TimeInvert ti0;
-  ti0 = t0 / (t1 * t2);
-  iti0 = ti0.GetHighPrecision().GetInteger();
-  // This check is not quite working yet.
-  //  CheckTime("ops 13", iti0, (int64_t)(it0/(it1*it2)), ok);
+  ASSERT_EQ((t0 * t1 / ((t0-t1) * t0)).GetDouble (),
+            (t0.GetSeconds () * t1.GetSeconds () / ((t0.GetSeconds () - t1.GetSeconds()) * t0.GetSeconds ())));
+  return false;
+}
 
-  Scalar s0 = t0 / t1;
-  CheckTimeSec("ops 14", s0.GetDouble(), it0/it1, ok);
+class TimeStepTestCase : public TestCase
+{
+public:
+  TimeStepTestCase ();
+  virtual bool DoRun (void);
+};
 
-  Scalar s1;
-  s1 = t0 * t1 / (t2 * t0);
-  CheckTimeSec("ops 15", s1.GetDouble(), it0*it1/(it2*it0), ok);
-
-  TimeUnit<0> tu0;
-  tu0 = s0;
-  CheckTimeSec("ops 16", tu0.GetDouble(), s0.GetDouble(), ok);
-
-  TimeUnit<1> tu1;
-  tu1 = t0;
-  CheckTimeSec("ops 17", tu1.GetSeconds(), it0, ok);
+TimeStepTestCase::TimeStepTestCase ()
+  : TestCase("Check boundaries of TimeStep")
+{}
+bool
+TimeStepTestCase::DoRun (void)
+{
+  Time tooBig = TimeStep (0x8000000000000000LL);
+  NS_TEST_ASSERT_MSG_EQ (tooBig.IsNegative (), true, "Is not negative ?");
+  tooBig = TimeStep (0xffffffffffffffffLL);
+  NS_TEST_ASSERT_MSG_EQ (tooBig.IsNegative (), true, "Is not negative ?");
+  tooBig = TimeStep (0x7fffffffffffffffLL);
+  NS_TEST_ASSERT_MSG_EQ (tooBig.IsPositive (), true, "Is not negative ?");
+  tooBig += TimeStep (1);
+  NS_TEST_ASSERT_MSG_EQ (tooBig.IsNegative (), true, "Is not negative ?");
+  return false;
+}
 
-  TimeUnit<2> tu2;
-  tu2 = t0 * t1;
-  CheckTimeSec("ops 18", tu2.GetHighPrecision().GetInteger()/(1e18), 
-               it0 * it1, ok);
-  itu2 = tu2.GetHighPrecision().GetInteger()/(1e18);
-  
-  TimeUnit<3> tu3;
-  tu3 = t0 / Scalar(10e6) * tu2;
-  CheckTimeSec("ops 19", tu3.GetHighPrecision().GetInteger()/(1e27), 
-               it0 / 1000000 * itu2, ok);
-  itu3 = tu3.GetHighPrecision().GetInteger()/(1e27);
+class GlobalPrecisionTestCase : public TestCase
+{
+public:
+  GlobalPrecisionTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
+
+GlobalPrecisionTestCase::GlobalPrecisionTestCase ()
+  : TestCase ("Check that global value actually changes the underlying precision")
+{}
+#define CHECK_PRECISION(prec) \
+  Config::SetGlobal ("TimeStepPrecision", StringValue (#prec)); \
+  NS_TEST_ASSERT_MSG_EQ(TimeStepPrecision::Get(), TimeStepPrecision::prec, "Could not set precision " << #prec)
+bool 
+GlobalPrecisionTestCase::DoRun (void)
+{
+  CHECK_PRECISION(S);
+  CHECK_PRECISION(MS);
+  CHECK_PRECISION(US);
+  CHECK_PRECISION(NS);
+  CHECK_PRECISION(PS);
+  CHECK_PRECISION(FS);
+  return false;
 }
 
-void TimeTests::CheckConversions(uint64_t tval, bool *ok, bool verbose) 
+void 
+GlobalPrecisionTestCase::DoTeardown (void)
 {
-  Time t_sec, t_ms, t_us, t_ns, t_ps, t_fs;
-
-  if (verbose) 
-    {
-      std::cout << std::endl << "Check conversions: " << tval << std::endl;
-    }
-
-  // First check the seconds
-  t_sec = Seconds((double)tval);
-  CheckTimeSec("conv sec sec", t_sec.GetSeconds(), (double)tval, ok);
-  CheckTime("conv sec ms", t_sec.GetMilliSeconds(), (int64_t)(tval*1e3), ok, 1e3);
-  CheckTime("conv sec us", t_sec.GetMicroSeconds(), (int64_t)(tval*1e6), ok, 1e6);
-  CheckTime("conv sec ns", t_sec.GetNanoSeconds(), (int64_t)(tval*1e9), ok, 1e9);
-  CheckTime("conv sec ps", t_sec.GetPicoSeconds(), 
-            (int64_t)(tval*1e12), ok, 1e12);
-  CheckTime("conv sec fs", t_sec.GetFemtoSeconds(), 
-            (int64_t)(tval*1e15), ok, 1e15);
-
-  // Then check the milliseconds
-  t_ms = MilliSeconds(tval);
-  CheckTimeSec("conv ms sec", t_ms.GetSeconds(), (double)tval/1e3, ok);
-  CheckTime("conv ms ms", t_ms.GetMilliSeconds(), (int64_t)(tval), ok, 1e3);
-  CheckTime("conv ms us", t_ms.GetMicroSeconds(), (int64_t)(tval*1e3), ok, 1e6);
-  CheckTime("conv ms ns", t_ms.GetNanoSeconds(), (int64_t)(tval*1e6), ok, 1e9);
-  CheckTime("conv ms ps", t_ms.GetPicoSeconds(), (int64_t)(tval*1e9), ok, 1e12);
-  CheckTime("conv ms fs", t_ms.GetFemtoSeconds(), (int64_t)(tval*1e12), ok, 1e15);
+  TimeStepPrecision::Set (TimeStepPrecision::NS);
+}
 
-  // Then check the microseconds
-  t_us = MicroSeconds(tval);
-  CheckTimeSec("conv us sec", t_us.GetSeconds(), (double)tval/1e6, ok);
-  CheckTime("conv us ms", t_us.GetMilliSeconds(), (int64_t)(tval/1e3), ok, 1e3);
-  CheckTime("conv us us", t_us.GetMicroSeconds(), (int64_t)(tval), ok, 1e6);
-  CheckTime("conv us ns", t_us.GetNanoSeconds(), (int64_t)(tval*1e3), ok, 1e9);
-  CheckTime("conv us ps", t_us.GetPicoSeconds(), (int64_t)(tval*1e6), ok, 1e12);
-  CheckTime("conv us fs", t_us.GetFemtoSeconds(), (int64_t)(tval*1e9), ok, 1e15);
-  
-  // Then check the nanoseconds
-  t_ns = NanoSeconds(tval);
-  CheckTimeSec("conv ns sec", t_ns.GetSeconds(), (double)tval/1e9, ok);
-  CheckTime("conv ns ms", t_ns.GetMilliSeconds(), (int64_t)(tval/1e6), ok, 1e3);
-  CheckTime("conv ns us", t_ns.GetMicroSeconds(), (int64_t)(tval/1e3), ok, 1e6);
-  CheckTime("conv ns ns", t_ns.GetNanoSeconds(), (int64_t)(tval), ok, 1e9);
-  CheckTime("conv ns ps", t_ns.GetPicoSeconds(), (int64_t)(tval*1e3), ok, 1e12);
-  CheckTime("conv ns fs", t_ns.GetFemtoSeconds(), (int64_t)(tval*1e6), ok, 1e15);
-  
-  // Then check the picoseconds
-  t_ps = PicoSeconds(tval);
-  CheckTimeSec("conv ps sec", t_ps.GetSeconds(), (double)tval/1e12, ok);
-  CheckTime("conv ps ms", t_ps.GetMilliSeconds(), (int64_t)(tval/1e9), ok, 1e3);
-  CheckTime("conv ps us", t_ps.GetMicroSeconds(), (int64_t)(tval/1e6), ok, 1e6);
-  CheckTime("conv ps ns", t_ps.GetNanoSeconds(), (int64_t)(tval/1e3), ok, 1e9);
-  CheckTime("conv ps ps", t_ps.GetPicoSeconds(), (int64_t)(tval), ok, 1e12);
-  CheckTime("conv ps fs", t_ps.GetFemtoSeconds(), (int64_t)(tval*1e3), ok, 1e15);
-  
-  // Then check the femtoseconds
-  t_fs = FemtoSeconds(tval);
-  CheckTimeSec("conv fs sec", t_fs.GetSeconds(), (double)tval/1e15, ok);
-  CheckTime("conv fs ms", t_fs.GetMilliSeconds(), (int64_t)(tval/1e12), ok, 1e3);
-  CheckTime("conv fs us", t_fs.GetMicroSeconds(), (int64_t)(tval/1e9), ok, 1e6);
-  CheckTime("conv fs ns", t_fs.GetNanoSeconds(), (int64_t)(tval/1e6), ok, 1e9);
-  CheckTime("conv fs ps", t_fs.GetPicoSeconds(), (int64_t)(tval/1e3), ok, 1e12);
-  CheckTime("conv fs fs", t_fs.GetFemtoSeconds(), (int64_t)(tval), ok, 1e15);
+class ConversionTestCase : public TestCase
+{
+public:
+  ConversionTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
+};
 
-  
+ConversionTestCase::ConversionTestCase ()
+  : TestCase ("Check crazy time conversions")
+{}
+
+void ConversionTestCase::DoTeardown (void)
+{
+  TimeStepPrecision::Set (TimeStepPrecision::NS);
 }
 
-void TimeTests::CheckPrecision(TimeStepPrecision::precision_t prec, uint64_t val, bool *ok, 
-                               bool verbose) 
-{
-  if (verbose) 
-    {
-      std::cout << "check precision 10^-" << prec << std::endl;
-    }
-
-  TimeStepPrecision::Set (prec);
-  if (TimeStepPrecision::Get () != prec) 
-    {
-      ok = false;
-    }
+#define CHECK_CONVERSIONS(tmp)                                          \
+  do {                                                                  \
+    double val = tmp;                                                   \
+    Time t_sec = Seconds(val);                                          \
+    ASSERT_MSG_EQ(t_sec.GetSeconds(), val*1e0, 1e0, "conv sec s");          \
+    ASSERT_MSG_EQ_INT(t_sec.GetMilliSeconds(), val*1e3, 1e3, "conv sec ms"); \
+    ASSERT_MSG_EQ_INT(t_sec.GetMicroSeconds(), val*1e6, 1e6, "conv sec us"); \
+    ASSERT_MSG_EQ_INT(t_sec.GetNanoSeconds(), val*1e9, 1e9, "conv sec ns"); \
+    ASSERT_MSG_EQ_INT(t_sec.GetPicoSeconds(), val*1e12, 1e12, "conv sec ps"); \
+    ASSERT_MSG_EQ_INT(t_sec.GetFemtoSeconds(), val*1e15, 1e15, "conv sec fs"); \
+    uint64_t int_val = (uint64_t)val;                                  \
+    Time t_ms = MilliSeconds(int_val);                                 \
+    ASSERT_MSG_EQ(t_ms.GetSeconds(), val*1e-3, 1e0, "conv ms s");       \
+    ASSERT_MSG_EQ_INT(t_ms.GetMilliSeconds(), val*1e0, 1e3, "conv ms ms");     \
+    ASSERT_MSG_EQ_INT(t_ms.GetMicroSeconds(), val*1e3, 1e6, "conv ms us"); \
+    ASSERT_MSG_EQ_INT(t_ms.GetNanoSeconds(), val*1e6, 1e9, "conv ms ns");  \
+    ASSERT_MSG_EQ_INT(t_ms.GetPicoSeconds(), val*1e9, 1e12, "conv ms fs"); \
+    ASSERT_MSG_EQ_INT(t_ms.GetFemtoSeconds(), val*1e12, 1e15, "conv ms ps"); \
+    Time t_us = MicroSeconds(int_val);                                     \
+    ASSERT_MSG_EQ(t_us.GetSeconds(), val*1e-6, 1e0, "conv us s");       \
+    ASSERT_MSG_EQ_INT(t_us.GetMilliSeconds(), val*1e-3, 1e3, "conv us ms"); \
+    ASSERT_MSG_EQ_INT(t_us.GetMicroSeconds(), val*1e0, 1e6, "conv us us");     \
+    ASSERT_MSG_EQ_INT(t_us.GetNanoSeconds(), val*1e3, 1e9, "conv us ns");  \
+    ASSERT_MSG_EQ_INT(t_us.GetPicoSeconds(), val*1e6, 1e12, "conv us ps"); \
+    ASSERT_MSG_EQ_INT(t_us.GetFemtoSeconds(), val*1e9, 1e15, "conv us fs"); \
+    Time t_ns = NanoSeconds(int_val);                                      \
+    ASSERT_MSG_EQ(t_ns.GetSeconds(), val*1e-9, 1e0, "conv ns s");       \
+    ASSERT_MSG_EQ_INT(t_ns.GetMilliSeconds(), val*1e-6, 1e3, "conv ns ms"); \
+    ASSERT_MSG_EQ_INT(t_ns.GetMicroSeconds(), val*1e-3, 1e6, "conv ns us"); \
+    ASSERT_MSG_EQ_INT(t_ns.GetNanoSeconds(), val*1e0, 1e9, "conv ns ns");      \
+    ASSERT_MSG_EQ_INT(t_ns.GetPicoSeconds(), val*1e3, 1e12, "conv ns ps"); \
+    ASSERT_MSG_EQ_INT(t_ns.GetFemtoSeconds(), val*1e6, 1e15, "conv ns fs"); \
+    Time t_ps = PicoSeconds(int_val);                                      \
+    ASSERT_MSG_EQ(t_ps.GetSeconds(), val*1e-12, 1e0, "conv ps s");      \
+    ASSERT_MSG_EQ_INT(t_ps.GetMilliSeconds(), val*1e-9, 1e3, "conv ps ms"); \
+    ASSERT_MSG_EQ_INT(t_ps.GetMicroSeconds(), val*1e-6, 1e6, "conv ps us"); \
+    ASSERT_MSG_EQ_INT(t_ps.GetNanoSeconds(), val*1e-3, 1e9, "conv ps ns");  \
+    ASSERT_MSG_EQ_INT(t_ps.GetPicoSeconds(), val*1e0, 1e12, "conv ps ps");     \
+    ASSERT_MSG_EQ_INT(t_ps.GetFemtoSeconds(), val*1e3, 1e15, "conv ps fs"); \
+    Time t_fs = FemtoSeconds(int_val);                                     \
+    ASSERT_MSG_EQ(t_fs.GetSeconds(), val*1e-15, 1e0, "conv fs sec");    \
+    ASSERT_MSG_EQ_INT(t_fs.GetMilliSeconds(), val*1e-12, 1e3, "conv fs ms"); \
+    ASSERT_MSG_EQ_INT(t_fs.GetMicroSeconds(), val*1e-9, 1e6, "conv fs us"); \
+    ASSERT_MSG_EQ_INT(t_fs.GetNanoSeconds(), val*1e-6, 1e9, "conv fs ns");  \
+    ASSERT_MSG_EQ_INT(t_fs.GetPicoSeconds(), val*1e-3, 1e12, "conv fs ps"); \
+    ASSERT_MSG_EQ_INT(t_fs.GetFemtoSeconds(), val*1e0, 1e15, "conv fs fs");    \
+  } while (false)
 
-  /* These still need to be fixed.
-  // The smallest value that can be stored is 1x10^(-prec)
-  Time smallest = Seconds(pow(10,-prec));
-  CheckTimeSec("Prec small:     ", smallest.GetSeconds(), pow(10,-prec), ok, 0.1, 
-               true);
-  
-  double d_ts = pow(10,-prec) - pow(10, -(prec+3));
-  Time too_small = Seconds(d_ts);
-  CheckTimeSec("Prec too small: ", too_small.GetSeconds(), 0, ok, 0.1, true);
+bool
+ConversionTestCase::DoRun (void)
+{
+  CHECK_CONVERSIONS(5);
+  CHECK_CONVERSIONS(0);
+  CHECK_CONVERSIONS(783);
+  CHECK_CONVERSIONS(1132);
+  // triggers overflow
+  // XXX
+  // CHECK_CONVERSIONS(3341039);
+
+  TimeStepPrecision::Set (TimeStepPrecision::US);
+  CHECK_CONVERSIONS(7);
+  CHECK_CONVERSIONS(546);
+  CHECK_CONVERSIONS(6231);
+  // triggers overflow
+  // XXX
+  // CHECK_CONVERSIONS(1234639);
+
+  TimeStepPrecision::Set (TimeStepPrecision::MS);
+  CHECK_CONVERSIONS(3);
+  CHECK_CONVERSIONS(134);
+  CHECK_CONVERSIONS(2341);
+  // triggers overflow
+  // XXX
+  // CHECK_CONVERSIONS(8956239);
 
-  double d_la = 0xFFFFFFFF*pow(10,-prec);
-  Time largest = Seconds(d_la);
-  CheckTimeSec("Prec large:     ", largest.GetSeconds(), d_la, ok, 0.1, true);
+  TimeStepPrecision::Set (TimeStepPrecision::NS);
+  CHECK_CONVERSIONS(4);
+  CHECK_CONVERSIONS(342);
+  CHECK_CONVERSIONS(1327);
+  // triggers overflow
+  // XXX
+  // CHECK_CONVERSIONS(5439627);
 
-  double d_tl = (0xFFFFFFFF*pow(10,-prec)) + 1;
-  Time too_large = Seconds(d_tl);
-  if ((largest.GetSeconds() + 1) == too_large.GetSeconds())
-    std::cout << "Overflow did not occur." << std::endl;
+  TimeStepPrecision::Set (TimeStepPrecision::PS);
+  CHECK_CONVERSIONS(4);
+  CHECK_CONVERSIONS(342);
+  CHECK_CONVERSIONS(1327);
+  // triggers overflow
+  // XXX
+  // CHECK_CONVERSIONS(5439627);
 
-  NS_ASSERT(d_la+1 == d_tl);
-  */  
+  TimeStepPrecision::Set (TimeStepPrecision::NS);
+  CHECK_CONVERSIONS(12);
+
+  TimeStepPrecision::Set (TimeStepPrecision::S);
+  CHECK_CONVERSIONS(7);
+
+  TimeStepPrecision::Set (TimeStepPrecision::FS);
+  CHECK_CONVERSIONS(5);
+
+  return false;
 }
 
-void TimeTests::CheckTimeSec (std::string test_id, double actual, 
-                              double expected, bool *flag, double precMultFactor,
-                              bool verbose)
+static class TimeTestSuite : public TestSuite
 {
-  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
-  if ((actual < (expected-prec)) || (actual > (expected+prec))) 
-    {
-      std::cout << "FAIL " << test_id 
-                << " Expected:" << expected 
-                << " Actual: " << actual
-                << " Precision: " << prec << std::endl;
-      *flag = false;
-    } 
-  else 
-    {
-      if (verbose) 
-        {
-          std::cout << "PASS " << test_id 
-                    << " Expected:" << expected 
-                    << " Actual: " << actual
-                    << " Precision: " << prec << std::endl;
-        }
-    }
-}
+public:
+  TimeTestSuite()
+    : TestSuite("time", UNIT)
+  {
+    AddTestCase(new OldTimeTestCase());
+    AddTestCase(new OperationsTimeTestCase());
+    AddTestCase(new TimeStepTestCase());
+    AddTestCase(new GlobalPrecisionTestCase());
+    AddTestCase(new ConversionTestCase());
+  }
+} g_timeTestSuite;
 
-void TimeTests::CheckTime (std::string test_id, int64_t actual, 
-                           int64_t expected, bool *flag, double precMultFactor,
-                           bool verbose)
-{
-  double prec = pow(10,-((double)(ns3::TimeStepPrecision::Get ()))) * precMultFactor;
-  if ((actual < (expected-prec)) || (actual > (expected+prec))) 
-    {
-      std::cout << "FAIL " << test_id 
-                << " Expected:" << expected 
-                << " Actual: " << actual
-                << " Precision: " << prec << std::endl;
-      *flag = false;
-    } 
-  else 
-    {
-      if (verbose) 
-        {
-          std::cout << "PASS " << test_id 
-                    << " Expected:" << expected 
-                    << " Actual: " << actual 
-                    << " Precision: " << prec << std::endl;
-        }
-    }
-}
-
-
-static TimeTests g_time_tests;
-  
-}
-
-#endif /* RUN_SELF_TESTS */
+} // namespace ns3
--- a/src/simulator/timer.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/timer.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -167,9 +167,9 @@
 
 } // namespace ns3
 
-
-#ifdef RUN_SELF_TESTS
 #include "ns3/test.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
 
 namespace {
 void bari (int)
@@ -192,15 +192,61 @@
 {}
 void barcip (const int *)
 {}
-}
+} // anonymous namespace
 
 namespace ns3 {
 
-class TimerTests : public Test
+class TimerStateTestCase : public TestCase
 {
 public:
-  TimerTests ();
-  virtual bool RunTests (void);
+  TimerStateTestCase ();
+  virtual bool DoRun (void);
+};
+
+TimerStateTestCase::TimerStateTestCase ()
+  : TestCase ("Check correct state transitions")
+{}
+bool 
+TimerStateTestCase::DoRun (void)
+{
+  Timer timer = Timer (Timer::CANCEL_ON_DESTROY);
+
+  timer.SetFunction (&bari);
+  timer.SetArguments (1);
+  timer.SetDelay (Seconds (10.0));
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsRunning (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.IsExpired (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsSuspended (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.GetState (), Timer::EXPIRED, "");
+  timer.Schedule ();
+  NS_TEST_ASSERT_MSG_EQ (timer.IsRunning (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsExpired (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsSuspended (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.GetState (), Timer::RUNNING, "");
+  timer.Suspend ();
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsRunning (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsExpired (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.IsSuspended (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.GetState (), Timer::SUSPENDED, "");
+  timer.Resume ();
+  NS_TEST_ASSERT_MSG_EQ (timer.IsRunning (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsExpired (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsSuspended (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.GetState (), Timer::RUNNING, "");
+  timer.Cancel ();
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsRunning (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.IsExpired (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (!timer.IsSuspended (), true, "");
+  NS_TEST_ASSERT_MSG_EQ (timer.GetState (), Timer::EXPIRED, "");
+  return false;
+}
+
+class TimerTemplateTestCase : public TestCase
+{
+public:
+  TimerTemplateTestCase ();
+  virtual bool DoRun (void);
+  virtual void DoTeardown (void);
   void bazi (int) {}
   void baz2i (int, int) {}
   void baz3i (int, int, int) {}
@@ -213,45 +259,15 @@
   void bazcip (const int *) {}
 };
 
-TimerTests::TimerTests ()
-  : Test ("Timer")
+TimerTemplateTestCase::TimerTemplateTestCase ()
+  : TestCase ("Check that template magic is working")
 {}
 
 bool
-TimerTests::RunTests (void)
+TimerTemplateTestCase::DoRun (void)
 {
-  bool result = true;
-
   Timer timer = Timer (Timer::CANCEL_ON_DESTROY);
 
-  timer.SetFunction (&bari);
-  timer.SetArguments (1);
-  timer.SetDelay (Seconds (10.0));
-  NS_TEST_ASSERT (!timer.IsRunning ());
-  NS_TEST_ASSERT (timer.IsExpired ());
-  NS_TEST_ASSERT (!timer.IsSuspended ());
-  NS_TEST_ASSERT_EQUAL (timer.GetState (), Timer::EXPIRED);
-  timer.Schedule ();
-  NS_TEST_ASSERT (timer.IsRunning ());
-  NS_TEST_ASSERT (!timer.IsExpired ());
-  NS_TEST_ASSERT (!timer.IsSuspended ());
-  NS_TEST_ASSERT_EQUAL (timer.GetState (), Timer::RUNNING);
-  timer.Suspend ();
-  NS_TEST_ASSERT (!timer.IsRunning ());
-  NS_TEST_ASSERT (!timer.IsExpired ());
-  NS_TEST_ASSERT (timer.IsSuspended ());
-  NS_TEST_ASSERT_EQUAL (timer.GetState (), Timer::SUSPENDED);
-  timer.Resume ();
-  NS_TEST_ASSERT (timer.IsRunning ());
-  NS_TEST_ASSERT (!timer.IsExpired ());
-  NS_TEST_ASSERT (!timer.IsSuspended ());
-  NS_TEST_ASSERT_EQUAL (timer.GetState (), Timer::RUNNING);
-  timer.Cancel ();
-  NS_TEST_ASSERT (!timer.IsRunning ());
-  NS_TEST_ASSERT (timer.IsExpired ());
-  NS_TEST_ASSERT (!timer.IsSuspended ());
-  NS_TEST_ASSERT_EQUAL (timer.GetState (), Timer::EXPIRED);
-
   int a = 0;
   int &b = a;
   const int &c = a;
@@ -277,11 +293,11 @@
   timer.SetDelay (Seconds (1.0));
   timer.Schedule ();
 
-  timer.SetFunction (&TimerTests::bazi, this);
+  timer.SetFunction (&TimerTemplateTestCase::bazi, this);
   timer.SetArguments (3);
-  timer.SetFunction (&TimerTests::bazir, this);
+  timer.SetFunction (&TimerTemplateTestCase::bazir, this);
   timer.SetArguments (3);
-  timer.SetFunction (&TimerTests::bazcir, this);
+  timer.SetFunction (&TimerTemplateTestCase::bazcir, this);
   timer.SetArguments (3);
 
   timer.SetFunction (&bar2i);
@@ -292,29 +308,46 @@
   timer.SetArguments (1, 1, 1, 1);
   timer.SetFunction (&bar5i);
   timer.SetArguments (1, 1, 1, 1, 1);
+  // unsupported in simulator class
   //timer.SetFunction (&bar6i);
   //timer.SetArguments (1, 1, 1, 1, 1, 1);
 
-  timer.SetFunction (&TimerTests::baz2i, this);
+  timer.SetFunction (&TimerTemplateTestCase::baz2i, this);
   timer.SetArguments (1, 1);
-  timer.SetFunction (&TimerTests::baz3i, this);
+  timer.SetFunction (&TimerTemplateTestCase::baz3i, this);
   timer.SetArguments (1, 1, 1);
-  timer.SetFunction (&TimerTests::baz4i, this);
+  timer.SetFunction (&TimerTemplateTestCase::baz4i, this);
   timer.SetArguments (1, 1, 1, 1);
-  timer.SetFunction (&TimerTests::baz5i, this);
+  timer.SetFunction (&TimerTemplateTestCase::baz5i, this);
   timer.SetArguments (1, 1, 1, 1, 1);
-  //timer.SetFunction (&TimerTests::baz6i, this);
+  // unsupported in simulator class
+  //timer.SetFunction (&TimerTemplateTestCase::baz6i, this);
   //timer.SetArguments (1, 1, 1, 1, 1, 1);
 
-
   Simulator::Run ();
   Simulator::Destroy ();
-		  
-  return result;
+
+  return false;
+}
+
+void
+TimerTemplateTestCase::DoTeardown (void)
+{
+  Simulator::Run ();
+  Simulator::Destroy ();
 }
 
-TimerTests g_tests;
+static class TimerTestSuite : public TestSuite
+{
+public:
+  TimerTestSuite ()
+    : TestSuite ("timer", UNIT)
+  {
+    AddTestCase (new TimerStateTestCase ());
+    AddTestCase (new TimerTemplateTestCase ());
+  }
+} g_timerTestSuite;
 
 } // namespace ns3
 
-#endif /* RUN_SELF_TESTS */
+
--- a/src/simulator/watchdog.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/simulator/watchdog.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -59,56 +59,66 @@
 
 } // namespace ns3
 
-#ifdef RUN_SELF_TESTS
-
 #include "ns3/test.h"
 
 namespace ns3 {
 
-class WatchdogTests : public Test
+class WatchdogTestCase : public TestCase
 {
 public:
-  WatchdogTests ();
-  virtual bool RunTests (void);
-private:
+  WatchdogTestCase ();
+  virtual bool DoRun (void);
   void Expire (Time expected);
-  bool m_error;
+  bool m_expired;
+  Time m_expiredTime;
+  Time m_expiredArgument;
 };
 
-WatchdogTests::WatchdogTests ()
-  : Test ("Watchdog")
+WatchdogTestCase::WatchdogTestCase()
+  : TestCase ("Check that we can keepalive a watchdog")
 {}
 
 void
-WatchdogTests::Expire (Time expected)
+WatchdogTestCase::Expire (Time expected)
 {
-  bool result = true;
-  NS_TEST_ASSERT_EQUAL (Simulator::Now (), expected);
-  m_error = !result;
+  m_expired = true;
+  m_expiredTime = Simulator::Now ();
+  m_expiredArgument = expected;
 }
 
 bool
-WatchdogTests::RunTests (void)
+WatchdogTestCase::DoRun (void)
 {
-  bool result = true;
-
-  m_error = false;
+  m_expired = false;
+  m_expiredArgument = Seconds (0);
+  m_expiredTime = Seconds (0);
   Watchdog watchdog;
-  watchdog.SetFunction (&WatchdogTests::Expire, this);
+  watchdog.SetFunction (&WatchdogTestCase::Expire, this);
   watchdog.SetArguments (MicroSeconds (40));
   watchdog.Ping (MicroSeconds (10));
   Simulator::Schedule (MicroSeconds (5), &Watchdog::Ping, &watchdog, MicroSeconds (20));
   Simulator::Schedule (MicroSeconds (20), &Watchdog::Ping, &watchdog, MicroSeconds (2));
   Simulator::Schedule (MicroSeconds (23), &Watchdog::Ping, &watchdog, MicroSeconds (17));
   Simulator::Run ();
-  NS_TEST_ASSERT (!m_error);
   Simulator::Destroy ();
+  NS_TEST_ASSERT_MSG_EQ (m_expired, true, "The timer did not expire ??");
+  NS_TEST_ASSERT_MSG_EQ (m_expiredTime, MicroSeconds (40), "The timer did not expire at the expected time ?");
+  NS_TEST_ASSERT_MSG_EQ (m_expiredArgument, MicroSeconds (40), "We did not get the right argument");
 
-  return result;
+  return false;
 }
 
-static WatchdogTests g_watchdogTests;
+
+
+static class WatchdogTestSuite : public TestSuite
+{
+public:
+  WatchdogTestSuite()
+    : TestSuite ("watchdog", UNIT)
+  {
+    AddTestCase (new WatchdogTestCase ());
+  }
+} g_watchdogTestSuite;
 
 } // namespace ns3
 
-#endif /* RUN_SELF_TESTS */
Binary file src/test/ns3tcp/ns3tcp-interop-response-vectors.pcap has changed
--- a/src/test/ns3tcp/ns3tcp-interop-test-suite.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/src/test/ns3tcp/ns3tcp-interop-test-suite.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -36,7 +36,7 @@
 
 NS_LOG_COMPONENT_DEFINE ("Ns3TcpInteropTest");
 
-const bool WRITE_VECTORS = false;           // hack hack hack
+const bool WRITE_VECTORS = false;           // set to true to write response vectors
 const uint32_t PCAP_LINK_TYPE = 1187373553; // Some large random number -- we use to verify data was written by this program
 const uint32_t PCAP_SNAPLEN   = 64;         // Don't bother to save much data
 
--- a/test.py	Wed Sep 30 20:15:41 2009 +0400
+++ b/test.py	Wed Sep 30 20:15:49 2009 +0400
@@ -41,20 +41,13 @@
 interesting_config_items = [
     "NS3_BUILDDIR",
     "NS3_MODULE_PATH",
-    "ENABLE_EMU",
-    "ENABLE_GSL",
-    "ENABLE_GTK_CONFIG_STORE",
-    "ENABLE_LIBXML2",
     "ENABLE_NSC",
-    "ENABLE_PYTHON_BINDINGS",
-    "ENABLE_PYTHON_SCANNING",
     "ENABLE_REAL_TIME",
-    "ENABLE_STATIC_NS3",
-    "ENABLE_SUDO",
-    "ENABLE_TAP",
-    "ENABLE_THREADING",
 ]
 
+ENABLE_NSC = False
+ENABLE_REAL_TIME = False
+
 #
 # A list of examples to run as smoke tests just to ensure that they remain 
 # buildable and runnable over time.  Also a condition under which to run
@@ -329,20 +322,23 @@
 def make_library_path():
     global LIBRARY_PATH
 
-    LIBRARY_PATH = "LD_LIBRARY_PATH='"        
+    LIBRARY_PATH = "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:'"        
 
     if sys.platform == "darwin":
         LIBRARY_PATH = "DYLD_LIBRARY_PATH='"
     elif sys.platform == "win32":
-        LIBRARY_PATH = "PATH='"
+        LIBRARY_PATH = "PATH=$PATH:'"
     elif sys.platform == "cygwin":
-        LIBRARY_PATH = "PATH='"
+        LIBRARY_PATH = "PATH=$PATH:'"
 
     for path in NS3_MODULE_PATH:
         LIBRARY_PATH = LIBRARY_PATH + path + ":"
 
     LIBRARY_PATH = LIBRARY_PATH + "'"
 
+    if options.verbose:
+        print "LIBRARY_PATH == %s" % LIBRARY_PATH
+
 def run_job_synchronously(shell_command, directory):
     cmd = "%s %s/%s/%s" % (LIBRARY_PATH, NS3_BUILDDIR, NS3_ACTIVE_VARIANT, shell_command)
     if options.verbose:
@@ -615,20 +611,30 @@
     # run them in parallel.  We're going to spin up a number of worker threads
     # that will run our test jobs for us.
     #
-    # XXX Need to figure out number of CPUs without the multiprocessing 
-    # dependency since multiprocessing is not standard `till Python 2.6
-    #
     input_queue = Queue.Queue(0)
     output_queue = Queue.Queue(0)
 
     jobs = 0
     threads=[]
 
-    try:
-        import multiprocessing
-        processors = multiprocessing.cpu_count()
-    except ImportError:
-        processors = 1
+    #
+    # In Python 2.6 you can just use multiprocessing module, but we don't want
+    # to introduce that dependency yet; so we jump through a few hoops.
+    #
+    processors = 1
+
+    if 'SC_NPROCESSORS_ONLN'in os.sysconf_names:
+        processors = os.sysconf('SC_NPROCESSORS_ONLN')
+    else:
+        proc = subprocess.Popen("sysctl -n hw.ncpu", shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout_results, stderr_results = proc.communicate()
+        if len(stderr_results) == 0:
+            processors = int(stdout_results)
+
+    #
+    # Now, spin up one thread per processor which will eventually mean one test
+    # per processor running concurrently.
+    #
     for i in range(processors):
         thread = worker_thread(input_queue, output_queue)
         threads.append(thread)
@@ -641,6 +647,7 @@
     # Dispatching will run with unlimited speed and the worker threads will 
     # execute as fast as possible from the queue.
     #
+    total_tests = 0
     for test in suite_list:
         if len(test):
             job = Job()
@@ -656,6 +663,7 @@
 
             input_queue.put(job)
             jobs = jobs + 1
+            total_tests = total_tests + 1
     
     #
     # We've taken care of the discovered or specified test suites.  Now we
@@ -715,6 +723,8 @@
 
                     input_queue.put(job)
                     jobs = jobs + 1
+                    total_tests = total_tests + 1
+
     elif len(options.example):
         #
         # If you tell me to run an example, I will try and run the example
@@ -733,6 +743,7 @@
 
         input_queue.put(job)
         jobs = jobs + 1
+        total_tests = total_tests + 1
 
     #
     # Tell the worker threads to pack up and go home for the day.  Each one
@@ -753,6 +764,9 @@
     # ignore them.  If there are real results, we always print PASS or FAIL to
     # standard out as a quick indication of what happened.
     #
+    passed_tests = 0
+    failed_tests = 0
+    crashed_tests = 0
     for i in range(jobs):
         job = output_queue.get()
         if job.is_break:
@@ -765,8 +779,13 @@
 
         if job.returncode == 0:
             status = "PASS"
+            passed_tests = passed_tests + 1
+        elif job.returncode == 1:
+            failed_tests = failed_tests + 1
+            status = "FAIL"
         else:
-            status = "FAIL"
+            crashed_tests = crashed_tests + 1
+            status = "CRASH"
 
         print "%s: %s %s" % (status, kind, job.display_name)
 
@@ -848,6 +867,11 @@
     f.close()
 
     #
+    # Print a quick summary of events
+    #
+    print "%d of %d tests passed (%d passed, %d failed, %d crashed)" % (passed_tests, total_tests, passed_tests, 
+                                                                        failed_tests, crashed_tests)
+    #
     # The last things to do are to translate the XML results file to "human
     # readable form" if the user asked for it (or make an XML file somewhere)
     #
--- a/utils/test-runner.cc	Wed Sep 30 20:15:41 2009 +0400
+++ b/utils/test-runner.cc	Wed Sep 30 20:15:49 2009 +0400
@@ -230,6 +230,7 @@
   // but we'll do it if asked.
   //
   bool result = false;
+  bool suiteRan = false;
 
   for (uint32_t i = 0; i < TestRunner::GetNTestSuites (); ++i)
     {
@@ -240,9 +241,19 @@
           testSuite->SetStream (pofs);
           testSuite->SetVerbose (doVerbose);
           result |= testSuite->Run ();
+          suiteRan = true;
         }
     }
 
   ofs.close();
+
+  //
+  // If we couldn't figure out how to run at least one test, then return an error
+  //
+  if (suiteRan == false)
+    {
+      return true;
+    }
+
   return result;
 }