go-teeworlds-protocol/chunk7/chunk_test.go

68 lines
1.3 KiB
Go
Raw Normal View History

2024-06-20 00:26:04 +00:00
package chunk7
2024-06-07 07:38:35 +00:00
import (
"reflect"
"testing"
)
2024-06-16 01:21:49 +00:00
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})
2024-06-17 04:24:08 +00:00
want := ChunkHeader{
Flags: ChunkFlags{
Vital: false,
2024-06-16 01:21:49 +00:00
Resend: false,
},
Size: 3713,
2024-06-17 04:24:08 +00:00
Seq: 0,
2024-06-16 01:21:49 +00:00
}
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})
2024-06-17 04:24:08 +00:00
want := ChunkHeader{
Flags: ChunkFlags{
Vital: true,
2024-06-16 01:21:49 +00:00
Resend: false,
},
Size: 58,
2024-06-17 04:24:08 +00:00
Seq: 1,
2024-06-16 01:21:49 +00:00
}
if !reflect.DeepEqual(header, want) {
t.Errorf("got %v, wanted %v", header, want)
}
}
2024-06-07 07:38:35 +00:00
func TestVitalHeader(t *testing.T) {
header := ChunkHeader{}
header.Unpack([]byte{0x40, 0x10, 0x0a})
2024-06-17 04:24:08 +00:00
want := ChunkHeader{
Flags: ChunkFlags{
Vital: true,
2024-06-07 07:38:35 +00:00
Resend: false,
},
Size: 16,
2024-06-17 04:24:08 +00:00
Seq: 10,
2024-06-07 07:38:35 +00:00
}
if !reflect.DeepEqual(header, want) {
t.Errorf("got %v, wanted %v", header, want)
}
}