utils/python-unit-tests.py
author Craig Dowell <craigdo@ee.washington.edu>
Wed, 17 Dec 2008 12:54:16 -0800
changeset 4030 2efae18e7379
parent 3929 909b0a724ed3
child 4319 f4a73242f151
permissions -rw-r--r--
Added tag ns-3.3-RC6 for changeset 4267fd454004
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
import unittest
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
import ns3
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
class TestSimulator(unittest.TestCase):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
    def testScheduleNow(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
        def callback(args):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
            self._args_received = args
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
            self._cb_time = ns3.Simulator.Now()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
        ns3.Simulator.Destroy()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
        self._args_received = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
        self._cb_time = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
        ns3.Simulator.ScheduleNow(callback, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
        ns3.Simulator.Run()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
        self.assertEqual(self._args_received, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
        self.assertEqual(self._cb_time.GetSeconds(), 0.0)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
    def testSchedule(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
        def callback(args):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
            self._args_received = args
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
            self._cb_time = ns3.Simulator.Now()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
        ns3.Simulator.Destroy()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
        self._args_received = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
        self._cb_time = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
        ns3.Simulator.Schedule(ns3.Seconds(123), callback, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
        ns3.Simulator.Run()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
        self.assertEqual(self._args_received, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
        self.assertEqual(self._cb_time.GetSeconds(), 123.0)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
    def testScheduleDestroy(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
        def callback(args):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
            self._args_received = args
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
            self._cb_time = ns3.Simulator.Now()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
        ns3.Simulator.Destroy()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
        self._args_received = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
        self._cb_time = None
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
        def null(): pass
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
        ns3.Simulator.Schedule(ns3.Seconds(123), null)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
        ns3.Simulator.ScheduleDestroy(callback, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
        ns3.Simulator.Run()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
        ns3.Simulator.Destroy()
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
        self.assertEqual(self._args_received, "args")
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
        self.assertEqual(self._cb_time.GetSeconds(), 123.0)
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
3731
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    45
    def testTimeComparison(self):
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    46
        self.assert_(ns3.Seconds(123) == ns3.Seconds(123))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    47
        self.assert_(ns3.Seconds(123) >= ns3.Seconds(123))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    48
        self.assert_(ns3.Seconds(123) <= ns3.Seconds(123))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    49
        self.assert_(ns3.Seconds(124) > ns3.Seconds(123))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    50
        self.assert_(ns3.Seconds(123) < ns3.Seconds(124))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    51
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    52
    def testTimeNumericOperations(self):
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    53
        self.assertEqual(ns3.Seconds(10) + ns3.Seconds(5), ns3.Seconds(15))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    54
        self.assertEqual(ns3.Seconds(10) - ns3.Seconds(5), ns3.Seconds(5))
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    55
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    56
        v1 = ns3.Scalar(5)*ns3.Seconds(10)
317f9dbccc2b New pybindgen and new API scanning, brings support for comparison operators and + - * / numeric operators.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3546
diff changeset
    57
        self.assertEqual(v1, ns3.Seconds(50))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
    def testConfig(self):
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
        ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.UintegerValue(123))
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
        # hm.. no Config.Get?
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
3414
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    63
    def testSocket(self):
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    64
        node = ns3.Node()
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    65
        ns3.AddInternetStack(node)
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    66
        self._received_packet = None
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
3414
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    68
        def rx_callback(socket):
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    69
            assert self._received_packet is None
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    70
            self._received_packet = socket.Recv()
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
3414
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    72
        sink = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    73
        sink.Bind(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), 80))
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    74
        sink.SetRecvCallback(rx_callback)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
3414
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    76
        source = ns3.Socket.CreateSocket(node, ns3.TypeId.LookupByName("ns3::UdpSocketFactory"))
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    77
        source.SendTo(ns3.Packet(19), 0, ns3.InetSocketAddress(ns3.Ipv4Address("127.0.0.1"), 80))
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
3414
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    79
        ns3.Simulator.Run()
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    80
        self.assert_(self._received_packet is not None)
48d69d8eac38 Rescan API; fix and enable the socket unit test, as it now works.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3408
diff changeset
    81
        self.assertEqual(self._received_packet.GetSize(), 19)
3431
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    82
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    83
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    84
    def testAttributes(self):
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    85
        ##
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    86
        ## Yes, I know, the GetAttribute interface for Python is
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    87
        ## horrible, we should fix this soon, I hope.
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    88
        ##
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    89
        queue = ns3.DropTailQueue()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    90
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    91
        queue.SetAttribute("MaxPackets", ns3.UintegerValue(123456))
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    92
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    93
        limit = ns3.UintegerValue()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    94
        queue.GetAttribute("MaxPackets", limit)
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    95
        self.assertEqual(limit.Get(), 123456)
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    96
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    97
        ## -- object pointer values
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    98
        mobility = ns3.RandomWaypointMobilityModel()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
    99
        ptr = ns3.PointerValue()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   100
        mobility.GetAttribute("Position", ptr)
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   101
        self.assertEqual(ptr.GetObject(), None)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
        
3431
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   103
        pos = ns3.ListPositionAllocator()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   104
        mobility.SetAttribute("Position", ns3.PointerValue(pos))
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   105
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   106
        ptr = ns3.PointerValue()
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   107
        mobility.GetAttribute("Position", ptr)
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   108
        self.assert_(ptr.GetObject() is not None)
3501
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   109
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   110
    def testIdentity(self):
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   111
        csma = ns3.CsmaNetDevice()
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   112
        channel = ns3.CsmaChannel()
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   113
        csma.Attach(channel)
3431
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   114
        
3501
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   115
        c1 = csma.GetChannel()
f725f0e0d6b7 Python: use hash() as temporary workaround to check if two objects with different wrappers are underneath the same.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3431
diff changeset
   116
        c2 = csma.GetChannel()
3431
ccf8108ce6d7 A couple of attribute python unit tests
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3414
diff changeset
   117
3546
cecda7126440 New PyBindGen, fixes python wrapper identity issue.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3501
diff changeset
   118
        self.assert_(c1 is c2)
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
3753
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   120
    def testTypeId(self):
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   121
        typeId1 = ns3.TypeId.LookupByNameFailSafe("ns3::UdpSocketFactory")
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   122
        self.assertEqual(typeId1.GetName (), "ns3::UdpSocketFactory")
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   123
        
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   124
        self.assertRaises(KeyError, ns3.TypeId.LookupByNameFailSafe, "__InvalidTypeName__")
a84a48233eb3 A more pythonic wrapper for ns3.TypeId.LookupByNameFailSafe
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3731
diff changeset
   125
3929
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   126
    def testCommandLine(self):
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   127
        cmd = ns3.CommandLine()
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   128
        cmd.AddValue("Test1", "this is a test option")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   129
        cmd.AddValue("Test2", "this is a test option")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   130
        cmd.AddValue("Test3", "this is a test option", variable="test_xxx")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   131
        cmd.Test1 = None
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   132
        cmd.Test2 = None
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   133
        cmd.test_xxx = None
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   134
        class Foo:
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   135
            pass
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   136
        foo = Foo()
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   137
        foo.test_foo = None
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   138
        cmd.AddValue("Test4", "this is a test option", variable="test_foo", namespace=foo)
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   139
        
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   140
        cmd.Parse(["python", "--Test1=value1", "--Test2=value2", "--Test3=123", "--Test4=xpto"])
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   141
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   142
        self.assertEqual(cmd.Test1, "value1")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   143
        self.assertEqual(cmd.Test2, "value2")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   144
        self.assertEqual(cmd.test_xxx, "123")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   145
        self.assertEqual(foo.test_foo, "xpto")
909b0a724ed3 Bug 289: CommandLine::AddValue is not wrapped
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3768
diff changeset
   146
3408
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
if __name__ == '__main__':
2cc40b3e4fa5 python bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
    unittest.main()