'Test that writeExtended handles data correctly.  Send extended data
up to the size of the window, splitting the extended data into packets
of length remoteMaxPacket.'

def test_writeExtended(self):

    cb = [False]
    def stubStopWriting():
        cb[0] = True
    self.channel.stopWriting = stubStopWriting
    self.channel.writeExtended(1, 'd')
    self.channel.writeExtended(1, 'a')
    self.channel.writeExtended(2, 't')
    self.assertFalse(self.channel.areWriting)
    self.assertTrue(cb[0])
    self.channel.addWindowBytes(20)
    self.channel.writeExtended(2, 'a')
    data = self.conn.extData[self.channel]
    self.assertEqual(data, [(1, 'da'), (2, 't'), (2, 'a')])
    self.assertEqual(self.channel.remoteWindowLeft, 16)
    self.channel.writeExtended(3, '12345678901')
    self.assertEqual(data, [(1, 'da'), (2, 't'), (2, 'a'), (3, '1234567890'), (3, '1')])
    self.assertEqual(self.channel.remoteWindowLeft, 5)
    cb[0] = False
    self.channel.writeExtended(4, '123456')
    self.assertFalse(self.channel.areWriting)
    self.assertTrue(cb[0])
    self.assertEqual(data, [(1, 'da'), (2, 't'), (2, 'a'), (3, '1234567890'), (3, '1'), (4, '12345')])
    self.assertEqual(self.channel.extBuf, [[4, '6']])
    self.assertEqual(self.channel.remoteWindowLeft, 0)
