-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_test.go
151 lines (142 loc) · 4.91 KB
/
frame_test.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package quic
import (
"testing"
"github.com/ami-GS/gQUIC/qtype"
. "github.com/smartystreets/goconvey/convey"
)
func TestFrameTypeString(t *testing.T) {
Convey("if type 0x00 - 0x17, String should return properly", t, func() {
testset := []string{
"PADDING",
"RST_STREAM",
"CONNECTION_CLOSE",
"APPLICATION_CLOSE",
"MAX_DATA",
"MAX_STREAM_DATA",
"MAX_STREAM_ID",
"PING",
"BLOCKED",
"STREAM_BLOCKED",
"STREAM_ID_BLOCKED",
"NEW_CONNECTION_ID",
"STOP_SENDING",
"ACK",
"PATH_CHALLENGE",
"PATH_RESPONSE",
"STREAM",
"STREAM",
"STREAM",
"STREAM",
"STREAM",
"STREAM",
"STREAM",
"STREAM",
"NO_SUCH_TYPE",
}
for i := uint8(0); i < 0x18; i++ {
ft := FrameType(i)
So(ft.String(), ShouldEqual, testset[i])
}
})
}
func TestStreamFrame(t *testing.T) {
Convey("NewStreamFrame returns stream frame", t, func() {
sf1 := NewStreamFrame(0, 0, false, true, false, []byte{0x01})
sType := 0x12
sfexpect := StreamFrame{
NewBaseFrame(FrameType(sType)),
&BaseStreamLevelFrame{qtype.StreamID(0)},
qtype.QuicInt(0), qtype.QuicInt(1), false, []byte{0x01}}
sfexpect.wire = []byte{0x12, 0, 1, 1}
So(sf1, ShouldResemble, &sfexpect)
})
}
func TestParseStreamFrame(t *testing.T) {
// Data can be nil when OFF == 0 and/or FIN == true
Convey("streamframetype:0x10, streamID:0, offset:absent, length:absent, data:fill all(only 0x00)", t, func() {
data := []byte{0x10, 0x00, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 0, false, false, false, []byte{0x00})
So(err, ShouldBeNil)
So(length, ShouldEqual, 3)
So(aFrame, ShouldResemble, eFrame)
})
Convey("streamframetype:0x14, streamID:0, offset:1, length:absent, data:fill all(only 0x00)", t, func() {
data := []byte{0x14, 0x00, 0x01, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 1, true, false, false, []byte{0x00})
So(err, ShouldBeNil)
So(length, ShouldEqual, 4)
So(aFrame, ShouldResemble, eFrame)
})
Convey("streamframetype:0x14, streamID:0, offset:0, length:absent, data:nil", t, func() {
data := []byte{0x14, 0x00, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 0, true, false, false, nil)
So(err, ShouldBeNil)
So(length, ShouldEqual, 3)
So(aFrame, ShouldResemble, eFrame)
})
Convey("streamframetype:0x12, streamID:0, offset:absent, length:1, data:0x00", t, func() {
data := []byte{0x12, 0x00, 0x01, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 0, false, true, false, []byte{0x00})
So(err, ShouldBeNil)
So(length, ShouldEqual, 4)
So(aFrame, ShouldResemble, eFrame)
})
Convey("streamframetype:0x17, streamID:0, offset:absent, length:absent, data:nil", t, func() {
data := []byte{0x11, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 0, false, false, true, nil)
So(err, ShouldBeNil)
So(length, ShouldEqual, 2)
So(aFrame, ShouldResemble, eFrame)
})
Convey("streamframetype:0x16, streamID:0, offset:0, length:0, data:fill all(only 0x00)", t, func() {
data := []byte{0x14, 0x00, 0x00, 0x00}
aFrame, length, err := ParseStreamFrame(data)
eFrame := NewStreamFrame(0, 0, true, false, false, []byte{0x00})
So(err, ShouldBeNil)
So(length, ShouldEqual, 4)
So(aFrame, ShouldResemble, eFrame)
})
}
func TestGenWireOfStreamFrame(t *testing.T) {
Convey("streamframetype:0x10, streamID:0, offset:absent, length:absent, data:fill all(only 0x00)", t, func() {
eWire := []byte{0x10, 0x00, 0x00}
Frame := NewStreamFrame(0, 0, false, false, false, []byte{0x00})
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
Convey("streamframetype:0x14, streamID:0, offset:1, length:absent, data:fill all(only 0x00)", t, func() {
eWire := []byte{0x14, 0x00, 0x01, 0x00}
Frame := NewStreamFrame(0, 1, true, false, false, []byte{0x00})
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
Convey("streamframetype:0x14, streamID:0, offset:0, length:absent, data:nil", t, func() {
eWire := []byte{0x14, 0x00, 0x00}
Frame := NewStreamFrame(0, 0, true, false, false, nil)
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
Convey("streamframetype:0x12, streamID:0, offset:absent, length:1, data:0x00", t, func() {
eWire := []byte{0x12, 0x00, 0x01, 0x00}
Frame := NewStreamFrame(0, 0, false, true, false, []byte{0x00})
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
Convey("streamframetype:0x17, streamID:0, offset:absent, length:absent, data:nil", t, func() {
eWire := []byte{0x11, 0x00}
Frame := NewStreamFrame(0, 0, false, false, true, nil)
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
Convey("streamframetype:0x16, streamID:0, offset:0, length:0, data:fill all(only 0x00)", t, func() {
eWire := []byte{0x14, 0x00, 0x00, 0x00}
Frame := NewStreamFrame(0, 0, true, false, false, []byte{0x00})
aWire := Frame.GetWire()
So(aWire, ShouldResemble, eWire)
})
}