def test_sendCurrentChunk_Partial_Empty(self): """Check that trying to send an empty chunk marked partial works""" P=NullPayloadRTP.NullPayloadPreFramer("dummy") Dummy = Axon.Component.component() P.link((P,"output"),(Dummy, "inbox")) sentData = "" P.currentchunk = sentData self.assertNotEqual(P.sendCurrentChunk(sendpartial=True),0, "Sending valid chunk should result in non-zero") self.assertEqual(len(P.currentchunk), 0, "Remainder of chunk should be empty") self.assertEqual(len(P.outboxes['output']), 1, "Should have 1 results in output") item = None while 1: try: item = Dummy.recv("inbox") except: break theOutput = item # theOutput = P.outboxes['output'][-1] # Take the last thing to be .appended self.assertEqual(theOutput.__class__, tuple, "The output should be a tuple") self.assertEqual(len(theOutput), 2, "The output should be a 2-tuple") timestamp, dataSent = theOutput self.assertEqual(len(dataSent),len(sentData)+4, "The chunk should be sent data size + 4") self.assertEqual(dataSent[4:],sentData, "The data should be the same as our original") expectedLength = len(sentData) expectedLengthAsString = NullPayloadRTP.packLengthAsString(expectedLength) self.assertEqual(expectedLengthAsString, dataSent[0:4], "Length has been packed as 4 octets") self.assertEqual(timestamp, 0, "The timestamp should be 0") self.assertEqual(P.timestamp, len(sentData)/P.sourceoctetrate, "The next timestamp we get should be the time of the partial chunk later")
def test_sendCurrentChunk_NonPartialSendTwo(self): """Check that sending one non-partial chunks works""" P=NullPayloadRTP.NullPayloadPreFramer("dummy") Dummy = Axon.Component.component() P.link((P,"output"),(Dummy, "inbox")) P.currentchunk = "A"*(P.chunksize*2+1) self.assertNotEqual(P.sendCurrentChunk(),0, "Sending valid chunk should result in non-zero") self.assertNotEqual(P.sendCurrentChunk(),0, "Sending valid chunk should result in non-zero") self.assertEqual(len(P.currentchunk), 1, "Incorrectly Trimmed off 'chunksize' octets") self.assertEqual(len(P.outboxes['output']), 2, "Should have 2 results in output") item = None while 1: try: item = Dummy.recv("inbox") except: break theOutput = item # theOutput = P.outboxes['output'][-1] # Take the last thing to be .appended self.assertEqual(theOutput.__class__, tuple, "The output should be a tuple") self.assertEqual(len(theOutput), 2, "The output should be a 2-tuple") timestamp, dataSent = theOutput self.assertEqual(len(dataSent),P.chunksize+4, "The chunk should be chunksize + 4") self.assertEqual(dataSent[4:],"A"*P.chunksize, "The data should be a 'chunksize' num of A's") expectedLength = P.chunksize expectedLengthAsString = NullPayloadRTP.packLengthAsString(expectedLength) self.assertEqual(expectedLengthAsString, dataSent[0:4], "Length has been packed as 4 octets") self.assertEqual(timestamp, P.chunksize/P.sourceoctetrate, "The timestamp should be 1 chunk period") self.assertEqual(P.timestamp, P.chunksize*2/P.sourceoctetrate, "The next timestamp we get should be 1 chunk later")
def test_sendCurrentChunk_Partial_Empty(self): """Check that trying to send an empty chunk marked partial works""" P = NullPayloadRTP.NullPayloadPreFramer("dummy") Dummy = Axon.Component.component() P.link((P, "output"), (Dummy, "inbox")) sentData = "" P.currentchunk = sentData self.assertNotEqual(P.sendCurrentChunk(sendpartial=True), 0, "Sending valid chunk should result in non-zero") self.assertEqual(len(P.currentchunk), 0, "Remainder of chunk should be empty") self.assertEqual(len(P.outboxes['output']), 1, "Should have 1 results in output") item = None while 1: try: item = Dummy.recv("inbox") except: break theOutput = item # theOutput = P.outboxes['output'][-1] # Take the last thing to be .appended self.assertEqual(theOutput.__class__, tuple, "The output should be a tuple") self.assertEqual(len(theOutput), 2, "The output should be a 2-tuple") timestamp, dataSent = theOutput self.assertEqual(len(dataSent), len(sentData) + 4, "The chunk should be sent data size + 4") self.assertEqual(dataSent[4:], sentData, "The data should be the same as our original") expectedLength = len(sentData) expectedLengthAsString = NullPayloadRTP.packLengthAsString( expectedLength) self.assertEqual(expectedLengthAsString, dataSent[0:4], "Length has been packed as 4 octets") self.assertEqual(timestamp, 0, "The timestamp should be 0") self.assertEqual( P.timestamp, len(sentData) / P.sourceoctetrate, "The next timestamp we get should be the time of the partial chunk later" )
def test_sendCurrentChunk_NonPartialSendTwo(self): """Check that sending one non-partial chunks works""" P = NullPayloadRTP.NullPayloadPreFramer("dummy") Dummy = Axon.Component.component() P.link((P, "output"), (Dummy, "inbox")) P.currentchunk = "A" * (P.chunksize * 2 + 1) self.assertNotEqual(P.sendCurrentChunk(), 0, "Sending valid chunk should result in non-zero") self.assertNotEqual(P.sendCurrentChunk(), 0, "Sending valid chunk should result in non-zero") self.assertEqual(len(P.currentchunk), 1, "Incorrectly Trimmed off 'chunksize' octets") self.assertEqual(len(P.outboxes['output']), 2, "Should have 2 results in output") item = None while 1: try: item = Dummy.recv("inbox") except: break theOutput = item # theOutput = P.outboxes['output'][-1] # Take the last thing to be .appended self.assertEqual(theOutput.__class__, tuple, "The output should be a tuple") self.assertEqual(len(theOutput), 2, "The output should be a 2-tuple") timestamp, dataSent = theOutput self.assertEqual(len(dataSent), P.chunksize + 4, "The chunk should be chunksize + 4") self.assertEqual(dataSent[4:], "A" * P.chunksize, "The data should be a 'chunksize' num of A's") expectedLength = P.chunksize expectedLengthAsString = NullPayloadRTP.packLengthAsString( expectedLength) self.assertEqual(expectedLengthAsString, dataSent[0:4], "Length has been packed as 4 octets") self.assertEqual(timestamp, P.chunksize / P.sourceoctetrate, "The timestamp should be 1 chunk period") self.assertEqual(P.timestamp, P.chunksize * 2 / P.sourceoctetrate, "The next timestamp we get should be 1 chunk later")