changeset 12:fd802a55be55

Added unit tests for frame sequence numbers.
author cmlenz
date Mon, 13 Jun 2005 12:38:05 +0000
parents 4d31bd0c3eba
children 21aa17f97522
files bitten/util/beep.py bitten/util/tests/beep.py
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/util/beep.py
+++ b/bitten/util/beep.py
@@ -427,6 +427,7 @@
 
     def send_close(self, channelno=0, code=200, handle_ok=None,
                    handle_error=None):
+
         def handle_reply(cmd, msgno, message):
             if handle_ok is not None and cmd == 'RPY':
                 del self.session.channels[channelno]
@@ -434,6 +435,7 @@
             if handle_error is not None and cmd == 'ERR':
                 elem = parse_xml(message.get_payload())
                 handle_error(int(elem.code), elem.gettext())
+
         xml = Element('close', number=channelno, code=code)
         return self.channel.send_msg(MIMEMessage(xml, BEEP_XML), handle_reply)
 
@@ -443,6 +445,7 @@
 
     def send_start(self, profiles, handle_ok=None, handle_error=None):
         channelno = self.session.channelno.next()
+
         def handle_reply(cmd, msgno, message):
             if handle_ok is not None and cmd == 'RPY':
                 elem = parse_xml(message.get_payload())
@@ -455,6 +458,7 @@
             if handle_error is not None and cmd == 'ERR':
                 elem = parse_xml(message.get_payload())
                 handle_error(int(elem.code), elem.gettext())
+
         xml = Element('start', number=channelno)[
             [Element('profile', uri=profile.URI) for profile in profiles]
         ]
--- a/bitten/util/tests/beep.py
+++ b/bitten/util/tests/beep.py
@@ -59,6 +59,16 @@
         self.assertEqual(('MSG', 0, 'foo bar'),
                          self.profile.handled_messages[0])
 
+    def test_handle_out_of_sync_frame(self):
+        """
+        Verify that the channel detects out-of-sync frames and bails.
+        """
+        channel = beep.Channel(self.session, 0, self.profile)
+        channel.handle_frame('MSG', 0, False, 0L, None, 'foo bar')
+        # The next sequence number should be 8; send 12 instead
+        self.assertRaises(beep.ProtocolError, channel.handle_frame, 'MSG', 0,
+                          False, 12L, None, 'foo baz')
+
     def test_send_single_frame_message(self):
         """
         Verify that the channel passes a sent message up to the session for
@@ -71,7 +81,20 @@
                          self.session.sent_messages[0])
         assert msgno in channel.msgnos.keys()
 
-    def test_send_message_msgno_inc(self):
+    def test_send_frames_seqno_incrementing(self):
+        """
+        Verify that the sequence numbers of outgoing frames are incremented as
+        expected.
+        """
+        channel = beep.Channel(self.session, 0, self.profile)
+        channel.send_msg(beep.MIMEMessage('foo bar'))
+        channel.send_rpy(0, beep.MIMEMessage('nil'))
+        self.assertEqual(('MSG', 0, 0, False, 0L, None, 'foo bar'),
+                         self.session.sent_messages[0])
+        self.assertEqual(('RPY', 0, 0, False, 8L, None, 'nil'),
+                         self.session.sent_messages[1])
+
+    def test_send_message_msgno_incrementing(self):
         """
         Verify that the message number is incremented for subsequent outgoing
         messages.
@@ -145,4 +168,4 @@
     return unittest.makeSuite(ChannelTestCase, 'test')
 
 if __name__ == '__main__':
-	unittest.main()
+    unittest.main()
Copyright (C) 2012-2017 Edgewall Software