def test_Transport(self):
        from rospy.impl.transport import Transport, INBOUND, OUTBOUND, BIDIRECTIONAL
        ids = []
        for d in [INBOUND, OUTBOUND, BIDIRECTIONAL]:
            t = Transport(d)
            self.assertEquals(d, t.direction)
            self.assertEquals("UNKNOWN", t.transport_type)            
            self.failIf(t.done)
            self.assertEquals(None, t.cleanup_cb)
            self.assertEquals('', t.endpoint_id)            
            self.assertEquals('unnamed', t.name)
            self.assertEquals(0, t.stat_bytes)            
            self.assertEquals(0, t.stat_num_msg)            
            self.failIf(t.id in ids)
            ids.append(t.id)

            t = Transport(d, 'a name')
            self.assertEquals(d, t.direction)
            self.assertEquals('a name', t.name)

        # test cleanup with and without a callback
        t = Transport(INBOUND)
        t.close()
        self.assert_(t.done)
        t = Transport(INBOUND)

        self.cleanup_obj = None
        def cleanup(obj):
            self.cleanup_obj = obj

        t.set_cleanup_callback(cleanup)
        self.assertEquals(t.cleanup_cb, cleanup)
        t.close()
        self.assert_(t.done)
        self.assertEquals(self.cleanup_obj, t)

        t = Transport(OUTBOUND)
        import traceback
        try:
            t.send_message('msg', 1)
            self.fail("send_message() should be abstract")
        except:
            traceback.print_exc()
        try:
            t.write_data('data')
            self.fail("write_data() should be abstract")
        except:
            traceback.print_exc()            
        t = Transport(INBOUND)
        try:
            t.receive_once()
            self.fail("receive_once() should be abstract")
        except: pass
        t = Transport(INBOUND)
        try:
            t.receive_loop()
            self.fail("receive_loop() should be abstract")
        except: pass
Example #2
0
    def test_Transport(self):
        from rospy.impl.transport import Transport, INBOUND, OUTBOUND, BIDIRECTIONAL
        ids = []
        for d in [INBOUND, OUTBOUND, BIDIRECTIONAL]:
            t = Transport(d)
            self.assertEquals(d, t.direction)
            self.assertEquals("UNKNOWN", t.transport_type)
            self.failIf(t.done)
            self.assertEquals(None, t.cleanup_cb)
            self.assertEquals('', t.endpoint_id)
            self.assertEquals('unnamed', t.name)
            self.assertEquals(0, t.stat_bytes)
            self.assertEquals(0, t.stat_num_msg)
            self.failIf(t.id in ids)
            ids.append(t.id)

            t = Transport(d, 'a name')
            self.assertEquals(d, t.direction)
            self.assertEquals('a name', t.name)

        # test cleanup with and without a callback
        t = Transport(INBOUND)
        t.close()
        self.assert_(t.done)
        t = Transport(INBOUND)

        self.cleanup_obj = None

        def cleanup(obj):
            self.cleanup_obj = obj

        t.set_cleanup_callback(cleanup)
        self.assertEquals(t.cleanup_cb, cleanup)
        t.close()
        self.assert_(t.done)
        self.assertEquals(self.cleanup_obj, t)

        t = Transport(OUTBOUND)
        import traceback
        try:
            t.send_message('msg', 1)
            self.fail("send_message() should be abstract")
        except:
            traceback.print_exc()
        try:
            t.write_data('data')
            self.fail("write_data() should be abstract")
        except:
            traceback.print_exc()
        t = Transport(INBOUND)
        try:
            t.receive_once()
            self.fail("receive_once() should be abstract")
        except:
            pass
        t = Transport(INBOUND)
        try:
            t.receive_loop()
            self.fail("receive_loop() should be abstract")
        except:
            pass