...
1
2
3
4
5
6
7 package quic
8
9 import "testing"
10
11 func TestSentPacket(t *testing.T) {
12 frames := []any{
13 byte(frameTypePing),
14 byte(frameTypeStreamBase),
15 uint64(1),
16 i64range[int64]{1 << 20, 1<<20 + 1024},
17 }
18
19 sent := newSentPacket()
20 for _, f := range frames {
21 switch f := f.(type) {
22 case byte:
23 sent.appendAckElicitingFrame(f)
24 case uint64:
25 sent.appendInt(f)
26 case i64range[int64]:
27 sent.appendOffAndSize(f.start, int(f.size()))
28 }
29 }
30
31 for i, want := range frames {
32 if done := sent.done(); done {
33 t.Fatalf("before consuming contents, sent.done() = true, want false")
34 }
35 switch want := want.(type) {
36 case byte:
37 if got := sent.next(); got != want {
38 t.Fatalf("%v: sent.next() = %v, want %v", i, got, want)
39 }
40 case uint64:
41 if got := sent.nextInt(); got != want {
42 t.Fatalf("%v: sent.nextInt() = %v, want %v", i, got, want)
43 }
44 case i64range[int64]:
45 if start, end := sent.nextRange(); start != want.start || end != want.end {
46 t.Fatalf("%v: sent.nextRange() = [%v,%v), want %v", i, start, end, want)
47 }
48 }
49 }
50 if done := sent.done(); !done {
51 t.Fatalf("after consuming contents, sent.done() = false, want true")
52 }
53 }
54
View as plain text