|
| 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 | +package quic |
| 6 | + |
| 7 | +import "testing" |
| 8 | + |
| 9 | +func TestSentVal(t *testing.T) { |
| 10 | + for _, test := range []struct { |
| 11 | + name string |
| 12 | + f func(*sentVal) |
| 13 | + wantIsSet bool |
| 14 | + wantShouldSend bool |
| 15 | + wantIsReceived bool |
| 16 | + wantShouldSendPTO bool |
| 17 | + }{{ |
| 18 | + name: "zero value", |
| 19 | + f: func(*sentVal) {}, |
| 20 | + wantIsSet: false, |
| 21 | + wantShouldSend: false, |
| 22 | + wantShouldSendPTO: false, |
| 23 | + wantIsReceived: false, |
| 24 | + }, { |
| 25 | + name: "v.set()", |
| 26 | + f: (*sentVal).set, |
| 27 | + wantIsSet: true, |
| 28 | + wantShouldSend: true, |
| 29 | + wantShouldSendPTO: true, |
| 30 | + wantIsReceived: false, |
| 31 | + }, { |
| 32 | + name: "v.setSent(0)", |
| 33 | + f: func(v *sentVal) { |
| 34 | + v.setSent(0) |
| 35 | + }, |
| 36 | + wantIsSet: true, |
| 37 | + wantShouldSend: false, |
| 38 | + wantShouldSendPTO: true, |
| 39 | + wantIsReceived: false, |
| 40 | + }, { |
| 41 | + name: "sent.set()", |
| 42 | + f: func(v *sentVal) { |
| 43 | + v.setSent(0) |
| 44 | + v.set() |
| 45 | + }, |
| 46 | + wantIsSet: true, |
| 47 | + wantShouldSend: false, |
| 48 | + wantShouldSendPTO: true, |
| 49 | + wantIsReceived: false, |
| 50 | + }, { |
| 51 | + name: "sent.setUnsent()", |
| 52 | + f: func(v *sentVal) { |
| 53 | + v.setSent(0) |
| 54 | + v.setUnsent() |
| 55 | + }, |
| 56 | + wantIsSet: true, |
| 57 | + wantShouldSend: true, |
| 58 | + wantShouldSendPTO: true, |
| 59 | + wantIsReceived: false, |
| 60 | + }, { |
| 61 | + name: "set.clear()", |
| 62 | + f: func(v *sentVal) { |
| 63 | + v.set() |
| 64 | + v.clear() |
| 65 | + }, |
| 66 | + wantIsSet: false, |
| 67 | + wantShouldSend: false, |
| 68 | + wantShouldSendPTO: false, |
| 69 | + wantIsReceived: false, |
| 70 | + }, { |
| 71 | + name: "v.setReceived()", |
| 72 | + f: (*sentVal).setReceived, |
| 73 | + wantIsSet: true, |
| 74 | + wantShouldSend: false, |
| 75 | + wantShouldSendPTO: false, |
| 76 | + wantIsReceived: true, |
| 77 | + }, { |
| 78 | + name: "v.ackOrLoss(!pnum, true)", |
| 79 | + f: func(v *sentVal) { |
| 80 | + v.setSent(1) |
| 81 | + v.ackOrLoss(0, true) // ack different packet containing the val |
| 82 | + }, |
| 83 | + wantIsSet: true, |
| 84 | + wantShouldSend: false, |
| 85 | + wantShouldSendPTO: false, |
| 86 | + wantIsReceived: true, |
| 87 | + }, { |
| 88 | + name: "v.ackOrLoss(!pnum, false)", |
| 89 | + f: func(v *sentVal) { |
| 90 | + v.setSent(1) |
| 91 | + v.ackOrLoss(0, false) // lose different packet containing the val |
| 92 | + }, |
| 93 | + wantIsSet: true, |
| 94 | + wantShouldSend: false, |
| 95 | + wantShouldSendPTO: true, |
| 96 | + wantIsReceived: false, |
| 97 | + }, { |
| 98 | + name: "v.ackOrLoss(pnum, false)", |
| 99 | + f: func(v *sentVal) { |
| 100 | + v.setSent(1) |
| 101 | + v.ackOrLoss(1, false) // lose same packet containing the val |
| 102 | + }, |
| 103 | + wantIsSet: true, |
| 104 | + wantShouldSend: true, |
| 105 | + wantShouldSendPTO: true, |
| 106 | + wantIsReceived: false, |
| 107 | + }, { |
| 108 | + name: "v.ackLatestOrLoss(!pnum, true)", |
| 109 | + f: func(v *sentVal) { |
| 110 | + v.setSent(1) |
| 111 | + v.ackLatestOrLoss(0, true) // ack different packet containing the val |
| 112 | + }, |
| 113 | + wantIsSet: true, |
| 114 | + wantShouldSend: false, |
| 115 | + wantShouldSendPTO: true, |
| 116 | + wantIsReceived: false, |
| 117 | + }, { |
| 118 | + name: "v.ackLatestOrLoss(pnum, true)", |
| 119 | + f: func(v *sentVal) { |
| 120 | + v.setSent(1) |
| 121 | + v.ackLatestOrLoss(1, true) // ack same packet containing the val |
| 122 | + }, |
| 123 | + wantIsSet: true, |
| 124 | + wantShouldSend: false, |
| 125 | + wantShouldSendPTO: false, |
| 126 | + wantIsReceived: true, |
| 127 | + }, { |
| 128 | + name: "v.ackLatestOrLoss(!pnum, false)", |
| 129 | + f: func(v *sentVal) { |
| 130 | + v.setSent(1) |
| 131 | + v.ackLatestOrLoss(0, false) // lose different packet containing the val |
| 132 | + }, |
| 133 | + wantIsSet: true, |
| 134 | + wantShouldSend: false, |
| 135 | + wantShouldSendPTO: true, |
| 136 | + wantIsReceived: false, |
| 137 | + }, { |
| 138 | + name: "v.ackLatestOrLoss(pnum, false)", |
| 139 | + f: func(v *sentVal) { |
| 140 | + v.setSent(1) |
| 141 | + v.ackLatestOrLoss(1, false) // lose same packet containing the val |
| 142 | + }, |
| 143 | + wantIsSet: true, |
| 144 | + wantShouldSend: true, |
| 145 | + wantShouldSendPTO: true, |
| 146 | + wantIsReceived: false, |
| 147 | + }} { |
| 148 | + var v sentVal |
| 149 | + test.f(&v) |
| 150 | + if got, want := v.isSet(), test.wantIsSet; got != want { |
| 151 | + t.Errorf("%v: v.isSet() = %v, want %v", test.name, got, want) |
| 152 | + } |
| 153 | + if got, want := v.shouldSend(), test.wantShouldSend; got != want { |
| 154 | + t.Errorf("%v: v.shouldSend() = %v, want %v", test.name, got, want) |
| 155 | + } |
| 156 | + if got, want := v.shouldSendPTO(false), test.wantShouldSend; got != want { |
| 157 | + t.Errorf("%v: v.shouldSendPTO(false) = %v, want %v", test.name, got, want) |
| 158 | + } |
| 159 | + if got, want := v.shouldSendPTO(true), test.wantShouldSendPTO; got != want { |
| 160 | + t.Errorf("%v: v.shouldSendPTO(true) = %v, want %v", test.name, got, want) |
| 161 | + } |
| 162 | + if got, want := v.isReceived(), test.wantIsReceived; got != want { |
| 163 | + t.Errorf("%v: v.isReceived() = %v, want %v", test.name, got, want) |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments