github.com/daeuniverse/quic-go@v0.0.0-20240413031024-943f218e0810/internal/protocol/stream_test.go (about) 1 package protocol 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 ) 7 8 var _ = Describe("Stream ID", func() { 9 It("InvalidStreamID is smaller than all valid stream IDs", func() { 10 Expect(InvalidStreamID).To(BeNumerically("<", 0)) 11 }) 12 13 It("says who initiated a stream", func() { 14 Expect(StreamID(4).InitiatedBy()).To(Equal(PerspectiveClient)) 15 Expect(StreamID(5).InitiatedBy()).To(Equal(PerspectiveServer)) 16 Expect(StreamID(6).InitiatedBy()).To(Equal(PerspectiveClient)) 17 Expect(StreamID(7).InitiatedBy()).To(Equal(PerspectiveServer)) 18 }) 19 20 It("tells the directionality", func() { 21 Expect(StreamID(4).Type()).To(Equal(StreamTypeBidi)) 22 Expect(StreamID(5).Type()).To(Equal(StreamTypeBidi)) 23 Expect(StreamID(6).Type()).To(Equal(StreamTypeUni)) 24 Expect(StreamID(7).Type()).To(Equal(StreamTypeUni)) 25 }) 26 27 It("tells the stream number", func() { 28 Expect(StreamID(0).StreamNum()).To(BeEquivalentTo(1)) 29 Expect(StreamID(1).StreamNum()).To(BeEquivalentTo(1)) 30 Expect(StreamID(2).StreamNum()).To(BeEquivalentTo(1)) 31 Expect(StreamID(3).StreamNum()).To(BeEquivalentTo(1)) 32 Expect(StreamID(8).StreamNum()).To(BeEquivalentTo(3)) 33 Expect(StreamID(9).StreamNum()).To(BeEquivalentTo(3)) 34 Expect(StreamID(10).StreamNum()).To(BeEquivalentTo(3)) 35 Expect(StreamID(11).StreamNum()).To(BeEquivalentTo(3)) 36 }) 37 38 Context("converting stream nums to stream IDs", func() { 39 It("handles 0", func() { 40 Expect(StreamNum(0).StreamID(StreamTypeBidi, PerspectiveClient)).To(Equal(InvalidStreamID)) 41 Expect(StreamNum(0).StreamID(StreamTypeBidi, PerspectiveServer)).To(Equal(InvalidStreamID)) 42 Expect(StreamNum(0).StreamID(StreamTypeUni, PerspectiveClient)).To(Equal(InvalidStreamID)) 43 Expect(StreamNum(0).StreamID(StreamTypeUni, PerspectiveServer)).To(Equal(InvalidStreamID)) 44 }) 45 46 It("handles the first", func() { 47 Expect(StreamNum(1).StreamID(StreamTypeBidi, PerspectiveClient)).To(Equal(StreamID(0))) 48 Expect(StreamNum(1).StreamID(StreamTypeBidi, PerspectiveServer)).To(Equal(StreamID(1))) 49 Expect(StreamNum(1).StreamID(StreamTypeUni, PerspectiveClient)).To(Equal(StreamID(2))) 50 Expect(StreamNum(1).StreamID(StreamTypeUni, PerspectiveServer)).To(Equal(StreamID(3))) 51 }) 52 53 It("handles others", func() { 54 Expect(StreamNum(100).StreamID(StreamTypeBidi, PerspectiveClient)).To(Equal(StreamID(396))) 55 Expect(StreamNum(100).StreamID(StreamTypeBidi, PerspectiveServer)).To(Equal(StreamID(397))) 56 Expect(StreamNum(100).StreamID(StreamTypeUni, PerspectiveClient)).To(Equal(StreamID(398))) 57 Expect(StreamNum(100).StreamID(StreamTypeUni, PerspectiveServer)).To(Equal(StreamID(399))) 58 }) 59 60 It("has the right value for MaxStreamCount", func() { 61 const maxStreamID = StreamID(1<<62 - 1) 62 for _, dir := range []StreamType{StreamTypeUni, StreamTypeBidi} { 63 for _, pers := range []Perspective{PerspectiveClient, PerspectiveServer} { 64 Expect(MaxStreamCount.StreamID(dir, pers)).To(BeNumerically("<=", maxStreamID)) 65 Expect((MaxStreamCount + 1).StreamID(dir, pers)).To(BeNumerically(">", maxStreamID)) 66 } 67 } 68 }) 69 }) 70 })