예제 #1
0
 def testEscapingSinkTransmitsFlagOctetCorrectly(self):
     mockSink = MockSink()
     escapingSink = EscapingSink(mockSink)
     escapingSink.writeFlag()
     escapingSink.schedule()
     self.assertTrue(escapingSink.isReady())
     self.assertEqual([EscapingSink.FLAG()], mockSink.items)
예제 #2
0
 def testEscapingSinkTransmitsOctetCorrectly(self):
     mockSink = MockSink()
     escapingSink = EscapingSink(mockSink)
     escapingSink.write(0x42)
     escapingSink.schedule()
     self.assertTrue(escapingSink.isReady())
     self.assertTrue([0x42] == mockSink.items)
 def testFrameTransmitterTransmitsNothingByDefault(self):
     tmp = MockSink()
     sink = EscapingSink(tmp)
     transmitter = FrameTransmitter(sink)
     for i in range(0, 5):
         transmitter.schedule()
         sink.schedule()
         
     self.assertEqual([], tmp.items)
 def testFrameTransmitterBecomesReadyOnlyOnceTransmissionComplete(self):
     tmp = MockSink()
     sink = EscapingSink(tmp)
     transmitter = FrameTransmitter(sink)
     transmitter.transmit(FrameTransmitter.ACK() + 0x24)
     
     for i in range(0, 5):
         self.assertFalse(transmitter.isReady())
         transmitter.schedule()
         sink.schedule()
     
     self.assertTrue(transmitter.isReady())
 def testFrameTransmitterTransmitsAckFrameCorrectly(self):
     tmp = MockSink()
     sink = EscapingSink(tmp)
     transmitter = FrameTransmitter(sink)
     transmitter.transmit(FrameTransmitter.ACK() + 0x24)
     
     for i in range(0, 5):
         transmitter.schedule()
         sink.schedule()
     
     crc = crc_ccitt_update(0xFFFF, FrameTransmitter.ACK() + 0x24)
     self.assertEqual([EscapingSink.FLAG(), FrameTransmitter.ACK() + 0x24, crc >> 8, crc & 0xFF, EscapingSink.FLAG()], tmp.items)
예제 #6
0
 def testEscapingSinkTransmitsEscapableOctetCorrectly(self):
     mockSink = MockSink()
     escapingSink = EscapingSink(mockSink)
     escapingSink.write(EscapingSink.FLAG())
     escapingSink.schedule()
     escapingSink.write(EscapingSink.ESCAPE())
     escapingSink.schedule()
     self.assertTrue(escapingSink.isReady())
     self.assertEqual([
         EscapingSink.ESCAPE(),
         EscapingSink.FLAG() ^ EscapingSink.MASK(),
         EscapingSink.ESCAPE(),
         EscapingSink.ESCAPE() ^ EscapingSink.MASK()
     ], mockSink.items)
    def testFrameTransmitterTransmitsUserFrameCorrectly(self):
        tmp = MockSink()
        sink = EscapingSink(tmp)
        transmitter = FrameTransmitter(sink)

        transmitter.transmit(0x00, [0x42])
        
        for i in range(0, 6):
            transmitter.schedule()
            sink.schedule()
            
        crc = crc_ccitt_update(0xFFFF, 0x00)
        crc = crc_ccitt_update(crc, 0x42)
        
        self.assertEqual([EscapingSink.FLAG(), 0x00, 0x42, crc >> 8, crc & 0xFF, EscapingSink.FLAG()], tmp.items)
예제 #8
0
 def testEscapingSinkBecomesReadyAfterTransmitting(self):
     mockSink = MockSink()
     escapingSink = EscapingSink(mockSink)
     escapingSink.write(0x42)
     escapingSink.schedule()
     self.assertTrue(escapingSink.isReady())