| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func testChunkForwardTSN() []byte { |
| 13 |
return []byte{0xc0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x3} |
| 14 |
} |
| 15 |
|
| 16 |
func TestChunkForwardTSN_Success(t *testing.T) { |
| 17 |
tt := []struct { |
| 18 |
binary []byte |
| 19 |
}{ |
| 20 |
{testChunkForwardTSN()}, |
| 21 |
{[]byte{0xc0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5}}, |
| 22 |
{[]byte{0xc0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6, 0x0, 0x7}}, |
| 23 |
} |
| 24 |
|
| 25 |
for i, tc := range tt { |
| 26 |
actual := &chunkForwardTSN{} |
| 27 |
err := actual.unmarshal(tc.binary) |
| 28 |
assert.NoErrorf(t, err, "failed to unmarshal #%d", i) |
| 29 |
|
| 30 |
b, err := actual.marshal() |
| 31 |
assert.NoError(t, err) |
| 32 |
assert.Equalf(t, tc.binary, b, "test %d not equal", i) |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
func TestChunkForwardTSNUnmarshal_Failure(t *testing.T) { |
| 37 |
tt := []struct { |
| 38 |
name string |
| 39 |
binary []byte |
| 40 |
}{ |
| 41 |
{"chunk header to short", []byte{0xc0}}, |
| 42 |
{"missing New Cumulative TSN", []byte{0xc0, 0x0, 0x0, 0x4}}, |
| 43 |
{"missing stream sequence", []byte{0xc0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x3, 0x0, 0x4, 0x0, 0x5, 0x0, 0x6}}, |
| 44 |
} |
| 45 |
|
| 46 |
for i, tc := range tt { |
| 47 |
actual := &chunkForwardTSN{} |
| 48 |
err := actual.unmarshal(tc.binary) |
| 49 |
assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name) |
| 50 |
} |
| 51 |
} |