golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/sent_packet_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build go1.21 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 // Record sent frames. 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 // Read the record. 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 }