Пример #1
0
   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")
Пример #2
0
 def test_handleShutdown_NoData(self):
     """Check that chuntting down the component with no more data to send functions correctly"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     P.currentchunk = ""
     self.assertEqual(
         P.handleShutdown(), 0,
         "Result should be zero indicating no more data to send")
Пример #3
0
    def test_handleShutdown_N_partial_Chunks(self):
        """Check that chuntting down the component with several partial chunks to send functions correctly"""
        P = NullPayloadRTP.NullPayloadPreFramer("dummy")
        Dummy = Axon.Component.component()
        P.link((P, "output"), (Dummy, "inbox"))
        chunkCount = 0
        chunksSent = 5
        P.currentchunk = "A" * (P.chunksize * chunksSent + 1)
        while P.handleShutdown():
            chunkCount += 1
            self.assertEqual(
                len(P.outboxes['output']), chunkCount,
                "Should have " + (str(chunkCount)) + " result(s) in output")
        self.assertEqual(P.currentchunk, "")
        item = None
        while 1:
            try:
                item = Dummy.recv("inbox")
            except:
                break
        lastChunk = item

        #      lastChunk = P.outboxes['output'][-1]
        (ts, chunk) = lastChunk
        lastData = chunk[4:]
        self.assertEqual("A", lastData)
Пример #4
0
   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")
Пример #5
0
    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"
        )
Пример #6
0
    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")
Пример #7
0
 def test_makeChunk_PartialCase_Large(self):
     """Check that a chunk with a size requiring only high end bits works"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     testString = "A" * ((1 << 24) + (2 << 16) + (0 << 8) + 0)
     self.assertEqual(len(testString),
                      ((1 << 24) + (2 << 16) + (0 << 8) + 0))
     chunk = P.makeChunk(testString)
     self.assertNotEqual(chunk, None)
     self.assertEqual(len(chunk), len(testString) + 4)
     self.assertEqual(chunk[0:4], chr(1) + chr(2) + chr(0) + chr(0))
Пример #8
0
 def test_init_MinArgs(self):
     """Check that __init__ with minimal args works (smoke test)"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     self.assertNotEqual(None, P, "Initialisation")
     self.assertEqual(P.sourcename, "dummy")
     self.assertEqual(P.sourcebitrate, 65536)
     self.assertEqual(P.sourceoctetrate, 8192)
     self.assertEqual(P.chunksize, 1400)
     self.assertEqual(P.currentchunk, "")
     self.assertEqual(P.timestamp, 0)
Пример #9
0
 def test_makeChunk_PartialCase_Little(self):
     """Check that creating a chunk with small payload (smaller than 65536 octets) functions"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     testString = "A" * ((0 << 24) + (0 << 16) + (3 << 8) + 4)
     self.assertEqual(len(testString),
                      ((0 << 24) + (0 << 16) + (3 << 8) + 4))
     chunk = P.makeChunk(testString)
     self.assertNotEqual(chunk, None)
     self.assertEqual(len(chunk), len(testString) + 4)
     self.assertEqual(chunk[0:4], chr(0) + chr(0) + chr(3) + chr(4))
Пример #10
0
 def test_makeChunk_FullCase(self):
     """Check that creating a chunk works, including length marker"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     testString = "A" * ((1 << 24) + (2 << 16) + (3 << 8) + 4)
     self.assertEqual(len(testString),
                      ((1 << 24) + (2 << 16) + (3 << 8) + 4))
     chunk = P.makeChunk(testString)
     self.assertNotEqual(chunk, None)
     self.assertEqual(len(chunk), len(testString) + 4)
     self.assertEqual(chunk[0:4], chr(1) + chr(2) + chr(3) + chr(4))
Пример #11
0
 def test_makeChunk_EmptyCase(self):
     """Check that empty chunks are created correctly"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     testString = "A" * ((0 << 24) + (0 << 16) + (0 << 8) + 0)
     self.assertEqual(len(testString),
                      ((0 << 24) + (0 << 16) + (0 << 8) + 0))
     chunk = P.makeChunk(testString)
     self.assertNotEqual(chunk, None)
     self.assertEqual(len(chunk), len(testString) + 4)
     self.assertEqual(len(chunk), 4)
     self.assertEqual(chunk[0:4], chr(0) + chr(0) + chr(0) + chr(0))
Пример #12
0
 def test_handleControl_ShutdownMessage(self):
     """Check that handling the control messages functions correctly with a shutdown message"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     P._deliver("shutdown", "control")
     lengthBefore = len(P.inboxes['control'])
     self.assertEqual(
         P.handleControl(), True,
         "With no shutdown messages, should return False (don't quit)")
     lengthAfter = len(P.inboxes['control'])
     self.assert_(lengthAfter == lengthBefore - 1,
                  "Processed message has been consumed")
Пример #13
0
 def test_init_AllArgs(self):
     """Smoke test with all user definable arguments"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy",
                                             sourcebitrate=32768,
                                             chunksize=700)
     self.assertNotEqual(None, P, "Initialisation")
     self.assertEqual(P.sourcename, "dummy")
     self.assertEqual(P.sourcebitrate, 32768)
     self.assertEqual(P.sourceoctetrate, 4096.0)
     self.assertEqual(P.chunksize, 700)
     self.assertEqual(P.currentchunk, "")
     self.assertEqual(P.timestamp, 0)
     self.assertEqual(P._dataSent, 0)
Пример #14
0
 def test_handleShutdown_N_whole_Chunks(self):
     """Check that chuntting down the component with several chunks to send functions correctly"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     Dummy = Axon.Component.component()
     P.link((P, "output"), (Dummy, "inbox"))
     chunkCount = 0
     chunksSent = 5
     P.currentchunk = "A" * (P.chunksize * chunksSent)
     while P.handleShutdown():
         chunkCount += 1
         self.assertEqual(
             len(P.outboxes['output']), chunkCount,
             "Should have " + (str(chunkCount)) + " result(s) in output")
     self.assertEqual(P.currentchunk, "")
Пример #15
0
 def test_handleShutdown_OneChunk(self):
     """Check that chuntting down the component with one more chunk to send functions correctly"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     Dummy = Axon.Component.component()
     P.link((P, "output"), (Dummy, "inbox"))
     P.currentchunk = "A" * P.chunksize
     self.assertEqual(
         P.handleShutdown(), 2,
         "Result should be non-zero indicating more data to send")
     self.assertEqual(len(P.outboxes['output']), 1,
                      "Should have 1 result in output")
     self.assertEqual(
         P.handleShutdown(), 0,
         "Result should be zero indicating no more data to send")
     self.assertEqual(len(P.outboxes['output']), 1,
                      "Should have 1 result in output")
Пример #16
0
    def test_updateTimestamp(self):
        """Check that updating the timestamp functions correctly, one off and cumulatively"""
        P = NullPayloadRTP.NullPayloadPreFramer("dummy")
        bytesSent = 0
        self.assert_(P.timestamp == 0)

        bytesToSend = "A" * (int(P.sourceoctetrate))
        P.updateTimestamp(bytesToSend)
        bytesSent += len(bytesToSend)
        self.assertEqual(P._dataSent, bytesSent)
        self.assertEqual(P.timestamp, bytesSent / P.sourceoctetrate)

        for i in [2, 4, 8, 16, 32, 64]:
            bytesToSend = "A" * (int(P.sourceoctetrate / i))
            P.updateTimestamp(bytesToSend)
            bytesSent += len(bytesToSend)
            self.assertEqual(P._dataSent, bytesSent)
            self.assertEqual(P.timestamp, bytesSent / P.sourceoctetrate)
Пример #17
0
 def test_sendCurrentChunk_EmptyNonPartial(self):
     """Check that sending an empty, non-partial chunk works"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     self.assertEqual(P.sendCurrentChunk(), 0,
                      "Sending empty, non-partial should result 0")
Пример #18
0
 def test_initialiseComponent(self):
     """Check that created components initialise correctly"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     self.assert_(P.initialiseComponent())
Пример #19
0
    def test_mainBody(self):
        """Test the mainbody of the NullPayloadRTP preframer"""
        P = NullPayloadRTP.NullPayloadPreFramer("dummy")
        Dummy = Axon.Component.component()
        P.link((P, "output"), (Dummy, "inbox"))
        self.assert_(
            P.mainBody(),
            "In the just initialised, quiescent state this should return a true value"
        )
        self.assertEqual(
            P.mainBody(), 5,
            "In fact should go all the way through the loop body")

        P.currentchunk = "A" * P.chunksize
        self.assertEqual(P.mainBody(), 1, "Should send the chunk and return")
        self.assertEqual(len(P.outboxes["output"]), 1,
                         "There should be one result")

        P._deliver("A" * (P.chunksize + 10), "recvsrc")
        self.assertEqual(len(P.inboxes["recvsrc"]), 1,
                         "There should be one message to recieve")
        self.assertEqual(P.mainBody(), 3,
                         "Should collect the chunk and return")
        self.assertEqual(len(P.inboxes["recvsrc"]), 0,
                         "There should be no messages to recieve")
        self.assertEqual(P.mainBody(), 1, "Should send the chunk and return")
        self.assertEqual(len(P.outboxes["output"]), 2,
                         "There should be two results")

        self.assertEqual(
            P.currentchunk, "A" * 10,
            "There should be some data left, but not a whole chunk")
        self.assertEqual(P.mainBody(), 5, "We are waiting for data")

        P._deliver("A" * (P.chunksize + 10), "recvsrc")
        self.assertEqual(len(P.inboxes["recvsrc"]), 1,
                         "There should be one message to recieve")
        self.assertEqual(P.mainBody(), 3,
                         "Should collect the chunk and return")
        self.assertEqual(len(P.inboxes["recvsrc"]), 0,
                         "There should be no messages to recieve")
        self.assertEqual(P.mainBody(), 1, "Should send the chunk and return")
        self.assertEqual(len(P.outboxes["output"]), 3,
                         "There should be three results")

        self.assertEqual(
            P.currentchunk, "A" * 20,
            "There should be some data left, but not a whole chunk - two fragments in fact"
        )
        self.assertEqual(P.mainBody(), 5, "We are waiting for data")

        P._deliver("garbage", "control")
        self.assertEqual(P.mainBody(), 4,
                         "Process the garbage control message")
        self.assert_(not P.quitFlag, "It shouldn't make us quit")

        P._deliver("shutdown", "control")
        self.assertEqual(P.mainBody(), 4,
                         "Process the garbage control message")
        self.assert_(P.quitFlag, "It should make us quit")

        self.assertEqual(
            P.mainBody(), 2,
            "We should have just sent a message during a shutdown phase")
        self.assertEqual("", P.currentchunk,
                         "The last partial chunk should have been sent")
        self.assertEqual(P.mainBody(), 0, "We are shutdown, and do no work")
        self.assertEqual(
            P.mainBody(), 0,
            "We are shutdown, and do no work, however many times called")
        self.assertEqual(
            P.mainBody(), 0,
            "We are shutdown, and do no work, however many times called")
Пример #20
0
 def test_CloseDownComponent(self):
     """Check that closing down the component doesn't raise an assert"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     P.closeDownComponent(
     )  # Does nothing at present. Here to handle asserts if valid later
Пример #21
0
 def test_handleControl_noMessage(self):
     """Check that handling the control messages functions correctly with no messages"""
     P = NullPayloadRTP.NullPayloadPreFramer("dummy")
     self.assertEqual(P.handleControl(), False,
                      "With no messages, should return False (don't quit)")