-
Notifications
You must be signed in to change notification settings - Fork 79
/
chunk_forward_tsn_test.go
57 lines (48 loc) · 1.36 KB
/
chunk_forward_tsn_test.go
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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testChunkForwardTSN() []byte {
return []byte{0xc0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x3}
}
func TestChunkForwardTSN_Success(t *testing.T) {
tt := []struct {
binary []byte
}{
{testChunkForwardTSN()},
{[]byte{0xc0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5}},
{[]byte{0xc0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6, 0x0, 0x7}},
}
for i, tc := range tt {
actual := &chunkForwardTSN{}
err := actual.unmarshal(tc.binary)
if err != nil {
t.Fatalf("failed to unmarshal #%d: %v", i, err)
}
b, err := actual.marshal()
if err != nil {
t.Fatalf("failed to marshal: %v", err)
}
assert.Equal(t, tc.binary, b, "test %d not equal", i)
}
}
func TestChunkForwardTSNUnmarshal_Failure(t *testing.T) {
tt := []struct {
name string
binary []byte
}{
{"chunk header to short", []byte{0xc0}},
{"missing New Cumulative TSN", []byte{0xc0, 0x0, 0x0, 0x4}},
{"missing stream sequence", []byte{0xc0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6}},
}
for i, tc := range tt {
actual := &chunkForwardTSN{}
err := actual.unmarshal(tc.binary)
if err == nil {
t.Errorf("expected unmarshal #%d: '%s' to fail.", i, tc.name)
}
}
}