File: sent_val_test.go

package info (click to toggle)
golang-golang-x-net 1%3A0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 8,636 kB
  • sloc: asm: 18; makefile: 12; sh: 7
file content (168 lines) | stat: -rw-r--r-- 4,530 bytes parent folder | download | duplicates (4)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import "testing"

func TestSentVal(t *testing.T) {
	for _, test := range []struct {
		name              string
		f                 func(*sentVal)
		wantIsSet         bool
		wantShouldSend    bool
		wantIsReceived    bool
		wantShouldSendPTO bool
	}{{
		name:              "zero value",
		f:                 func(*sentVal) {},
		wantIsSet:         false,
		wantShouldSend:    false,
		wantShouldSendPTO: false,
		wantIsReceived:    false,
	}, {
		name:              "v.set()",
		f:                 (*sentVal).set,
		wantIsSet:         true,
		wantShouldSend:    true,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "v.setSent(0)",
		f: func(v *sentVal) {
			v.setSent(0)
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "sent.set()",
		f: func(v *sentVal) {
			v.setSent(0)
			v.set()
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "sent.setUnsent()",
		f: func(v *sentVal) {
			v.setSent(0)
			v.setUnsent()
		},
		wantIsSet:         true,
		wantShouldSend:    true,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "set.clear()",
		f: func(v *sentVal) {
			v.set()
			v.clear()
		},
		wantIsSet:         false,
		wantShouldSend:    false,
		wantShouldSendPTO: false,
		wantIsReceived:    false,
	}, {
		name:              "v.setReceived()",
		f:                 (*sentVal).setReceived,
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: false,
		wantIsReceived:    true,
	}, {
		name: "v.ackOrLoss(!pnum, true)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackOrLoss(0, packetAcked) // ack different packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: false,
		wantIsReceived:    true,
	}, {
		name: "v.ackOrLoss(!pnum, packetLost)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackOrLoss(0, packetLost) // lose different packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "v.ackOrLoss(pnum, packetLost)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackOrLoss(1, packetLost) // lose same packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    true,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "v.ackLatestOrLoss(!pnum, packetAcked)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackLatestOrLoss(0, packetAcked) // ack different packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "v.ackLatestOrLoss(pnum, packetAcked)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackLatestOrLoss(1, packetAcked) // ack same packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: false,
		wantIsReceived:    true,
	}, {
		name: "v.ackLatestOrLoss(!pnum, packetLost)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackLatestOrLoss(0, packetLost) // lose different packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    false,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}, {
		name: "v.ackLatestOrLoss(pnum, packetLost)",
		f: func(v *sentVal) {
			v.setSent(1)
			v.ackLatestOrLoss(1, packetLost) // lose same packet containing the val
		},
		wantIsSet:         true,
		wantShouldSend:    true,
		wantShouldSendPTO: true,
		wantIsReceived:    false,
	}} {
		var v sentVal
		test.f(&v)
		if got, want := v.isSet(), test.wantIsSet; got != want {
			t.Errorf("%v: v.isSet() = %v, want %v", test.name, got, want)
		}
		if got, want := v.shouldSend(), test.wantShouldSend; got != want {
			t.Errorf("%v: v.shouldSend() = %v, want %v", test.name, got, want)
		}
		if got, want := v.shouldSendPTO(false), test.wantShouldSend; got != want {
			t.Errorf("%v: v.shouldSendPTO(false) = %v, want %v", test.name, got, want)
		}
		if got, want := v.shouldSendPTO(true), test.wantShouldSendPTO; got != want {
			t.Errorf("%v: v.shouldSendPTO(true) = %v, want %v", test.name, got, want)
		}
		if got, want := v.isReceived(), test.wantIsReceived; got != want {
			t.Errorf("%v: v.isReceived() = %v, want %v", test.name, got, want)
		}
	}
}