utils/python-unit-tests.py
changeset 3414 48d69d8eac38
parent 3408 2cc40b3e4fa5
child 3431 ccf8108ce6d7
equal deleted inserted replaced
3413:1d46345ab5d7 3414:48d69d8eac38
    57     def testConfig(self):
    57     def testConfig(self):
    58         ns3.Config.Set("ns3::OnOffApplication::PacketSize", ns3.UintegerValue(123))
    58         ns3.Config.Set("ns3::OnOffApplication::PacketSize", ns3.UintegerValue(123))
    59         ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.UintegerValue(123))
    59         ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.UintegerValue(123))
    60         # hm.. no Config.Get?
    60         # hm.. no Config.Get?
    61 
    61 
    62     if 0:
    62     def testSocket(self):
    63         # not yet: https://bugs.launchpad.net/pybindgen/+bug/246069
    63         node = ns3.Node()
    64         def testSocket(self):
    64         ns3.AddInternetStack(node)
    65             node = ns3.Node()
    65         self._received_packet = None
    66             ns3.AddInternetStack(node)
       
    67             self._received_packet = None
       
    68 
    66 
    69             def rx_callback(socket):
    67         def rx_callback(socket):
    70                 assert self._received_packet is None
    68             assert self._received_packet is None
    71                 self._received_packet = socket.Recv()
    69             self._received_packet = socket.Recv()
    72 
    70 
    73             sink = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
    71         sink = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
    74             sink.Bind(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), 80))
    72         sink.Bind(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), 80))
    75             sink.SetRecvCallback(rx_callback)
    73         sink.SetRecvCallback(rx_callback)
    76 
    74 
    77             source = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
    75         source = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
    78             source.SendTo(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), 80), ns3.Packet(19))
    76         source.SendTo(ns3.Packet(19), 0, ns3.InetSocketAddress(ns3.Ipv4Address("127.0.0.1"), 80))
    79 
    77 
    80             ns3.Simulator.Run()
    78         ns3.Simulator.Run()
    81             self.assert_(self._received_packet is not None)
    79         self.assert_(self._received_packet is not None)
    82             self.assertEqual(self._received_packet.GetSize(), 19)
    80         self.assertEqual(self._received_packet.GetSize(), 19)
    83         
    81         
    84 
    82 
    85 if __name__ == '__main__':
    83 if __name__ == '__main__':
    86     unittest.main()
    84     unittest.main()