Add more chunk header tests

This commit is contained in:
ChillerDragon 2024-06-16 09:21:49 +08:00
parent 2dd887de7d
commit a58425ea56
2 changed files with 71 additions and 1 deletions

View file

@ -5,10 +5,53 @@ import (
"testing"
)
func TestBrokenNonVitalHeader(t *testing.T) {
// this is a real vital header at a wrong offset
// so it creates a actually non vital header with a size that is bigger than usual
// verified results with teeworlds-network/twnet_parser python lib
header := ChunkHeader{}
// {0x40, 0x3a, 0x01}
header.Unpack([]byte{0x3a, 0x01})
want := ChunkHeader {
Flags: ChunkFlags {
Vital: false,
Resend: false,
},
Size: 3713,
Seq: 0,
}
if !reflect.DeepEqual(header, want) {
t.Errorf("got %v, wanted %v", header, want)
}
}
func TestVitalHeaderMapChange(t *testing.T) {
// generated by vanilla teeworlds 0.7 server
// verified with libtw2 wireshark dissector
header := ChunkHeader{}
header.Unpack([]byte{0x40, 0x3a, 0x01})
want := ChunkHeader {
Flags: ChunkFlags {
Vital: true,
Resend: false,
},
Size: 58,
Seq: 1,
}
if !reflect.DeepEqual(header, want) {
t.Errorf("got %v, wanted %v", header, want)
}
}
func TestVitalHeader(t *testing.T) {
header := ChunkHeader{}
header.Unpack([]byte{0x40, 0x10, 0x0a})
want := ChunkHeader {
Flags: ChunkFlags {
Vital: true,

View file

@ -6,6 +6,33 @@ import (
"testing"
)
func TestSplitterMapChange(t *testing.T) {
// real map change packet from a vanilla teeworlds 0.7 server
// dumped with the go client
// header := []byte{
// 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x04,
// }
payload := []byte {
0x3a, 0x01, 0x05, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x5f, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x73,
0x00, 0x91, 0xa7, 0xf2, 0xa0, 0x05, 0x8b, 0x11, 0x08, 0xa8, 0x15, 0xa9, 0x19, 0x38, 0xaf, 0xfd, 0xb6,
0xcb, 0xf1, 0xdb, 0x5a, 0xfc, 0x73, 0x34, 0xae, 0xa3, 0x68, 0xa7, 0xfa, 0x35, 0x54, 0x37, 0xf9, 0x39,
0x96, 0xd6, 0x05, 0x25, 0xef, 0x7b, 0x22, 0x40, 0x9d,
}
chunks := UnpackChunks(payload)
{
got := len(chunks)
want := 1
if want != got {
t.Errorf("got %v, wanted %v", got, want)
}
}
}
func TestSplitter(t *testing.T) {
// packet payload of real traffic
//