Add 4 tests in 'test_connection.py' and fix related bugs.
This commit is contained in:
1 parent
3ff7662684
commit
ce63626bb1
7 files changed
+457
-132
No files matched your search
+15
-15
@@ -19,19 +19,19 @@ class PacketSerializatonTest(unittest.TestCase):
|
||||
|
||||
packet = ChatPacket(context)
|
||||
packet.message = u"κόσμε"
|
||||
|
||||
|
||||
packet_buffer = PacketBuffer()
|
||||
packet.write(packet_buffer)
|
||||
|
||||
|
||||
packet_buffer.reset_cursor()
|
||||
# Read the length and packet id
|
||||
VarInt.read(packet_buffer)
|
||||
packet_id = VarInt.read(packet_buffer)
|
||||
self.assertEqual(packet_id, packet.id)
|
||||
|
||||
|
||||
deserialized = ChatPacket(context)
|
||||
deserialized.read(packet_buffer)
|
||||
|
||||
|
||||
self.assertEqual(packet.message, deserialized.message)
|
||||
|
||||
def test_compressed_packet(self):
|
||||
@@ -41,7 +41,7 @@ class PacketSerializatonTest(unittest.TestCase):
|
||||
msg = ''.join(choice(string.ascii_lowercase) for i in range(500))
|
||||
packet = ChatPacket(context)
|
||||
packet.message = msg
|
||||
|
||||
|
||||
self.write_read_packet(packet, 20)
|
||||
self.write_read_packet(packet, -1)
|
||||
|
||||
@@ -51,24 +51,24 @@ class PacketSerializatonTest(unittest.TestCase):
|
||||
|
||||
packet_buffer = PacketBuffer()
|
||||
packet.write(packet_buffer, compression_threshold)
|
||||
|
||||
|
||||
packet_buffer.reset_cursor()
|
||||
|
||||
|
||||
VarInt.read(packet_buffer)
|
||||
compressed_size = VarInt.read(packet_buffer)
|
||||
|
||||
|
||||
if compressed_size > 0:
|
||||
decompressed = decompress(packet_buffer.read(compressed_size))
|
||||
packet_buffer.reset()
|
||||
packet_buffer.send(decompressed)
|
||||
packet_buffer.reset_cursor()
|
||||
|
||||
|
||||
packet_id = VarInt.read(packet_buffer)
|
||||
self.assertEqual(packet_id, packet.id)
|
||||
|
||||
|
||||
deserialized = ChatPacket(context)
|
||||
deserialized.read(packet_buffer)
|
||||
|
||||
|
||||
self.assertEqual(packet.message, deserialized.message)
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ class PacketListenerTest(unittest.TestCase):
|
||||
|
||||
def test_listener(self):
|
||||
message = "hello world"
|
||||
|
||||
def test_packet(chat_packet):
|
||||
self.assertEqual(chat_packet.message, message)
|
||||
|
||||
@@ -83,10 +84,9 @@ class PacketListenerTest(unittest.TestCase):
|
||||
context = ConnectionContext(protocol_version=protocol_version)
|
||||
|
||||
listener = PacketListener(test_packet, ChatPacket)
|
||||
|
||||
packet = ChatPacket().set_values(message=message)
|
||||
|
||||
packet = ChatPacket(context).set_values(message=message)
|
||||
uncalled_packet = KeepAlivePacket().set_values(keep_alive_id=0)
|
||||
|
||||
|
||||
listener.call_packet(packet)
|
||||
listener.call_packet(uncalled_packet)
|
||||
|
||||
Reference in new issue
Block a user