twnet_parser/tests/chunk_header6_test.py
ChillerDragon 4f845ea7ee fix!: 0.6.5 chunk header
This change added a version flag to chunk header

``ChunkHeader()`` no longer works! You now have to do
``ChunkHeader(version = '0.6')`` or ``ChunkHeader(version = '0.7')``

This fixes 0.6 chunk header packing.
It has a suddle difference to 0.7 and it is now packed correctly.

Also unpacking 0.6.5 chunk headers is fixed by reading the correct size.
2024-03-10 20:10:43 +08:00

71 lines
2 KiB
Python

from twnet_parser.packet import \
ChunkHeaderParser
from twnet_parser.chunk_header import \
ChunkHeader
def test_chunk_header_unpack_bogus_vital() -> None:
# this is a non sense header
# but the values are verified with the C++
# implementation
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header6(b'\x40\x10\x0a')
assert header.flags.resend is False
assert header.flags.vital is True
assert header.size == 0
assert header.seq == 74
def test_chunk_header_unpack_vital_seq38() -> None:
# this is a non sense header
# but the values are verified with the C++
# implementation
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header6(b'\x40\x02\x26')
assert header.flags.resend is False
assert header.flags.vital is True
assert header.size == 2
assert header.seq == 38
def test_chunk_header_unpack_bogus_no_flags_size107() -> None:
# this is a non sense header
# but the values are verified with the C++
# implementation
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header6(b'\x06\x0b')
assert header.flags.resend is False
assert header.flags.vital is False
assert header.size == 107
assert header.seq == -1
def test_chunk_header_unpack_bogus_no_flags_size27() -> None:
# this is a non sense header
# but the values are verified with the C++
# implementation
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header6(b'\x01\x0b')
assert header.flags.resend is False
assert header.flags.vital is False
assert header.size == 27
assert header.seq == -1
def test_chunk_header_all_set() -> None:
# this is a non sense header
# but the values are verified with the C++
# implementation
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header6(b'\xff\xff\xff')
assert header.flags.resend is True
assert header.flags.vital is True
assert header.size == 1023
assert header.seq == 1023