forked from h2so5/utp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket_test.go
More file actions
64 lines (55 loc) · 969 Bytes
/
packet_test.go
File metadata and controls
64 lines (55 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package utp
import (
"io"
"reflect"
"testing"
)
func TestPacketBinary(t *testing.T) {
h := header{
typ: stFin,
ver: version,
id: 100,
t: 50000,
diff: 10000,
wnd: 65535,
seq: 100,
ack: 200,
}
e := []extension{
extension{
typ: extSelectiveAck,
payload: []byte{0, 1, 0, 1},
},
extension{
typ: extSelectiveAck,
payload: []byte{100, 0, 200, 0},
},
}
p := packet{
header: h,
ext: e,
payload: []byte("abcdefg"),
}
b, err := p.MarshalBinary()
if err != nil {
t.Fatal(err)
}
p2 := packet{payload: make([]byte, 0, mss)}
err = p2.UnmarshalBinary(b)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(p, p2) {
t.Errorf("expected packet of %v; got %v", p, p2)
}
}
func TestUnmarshalShortPacket(t *testing.T) {
b := make([]byte, 18)
p := packet{}
err := p.UnmarshalBinary(b)
if err == nil {
t.Fatal("UnmarshalBinary should fail")
} else if err != io.EOF {
t.Fatal(err)
}
}