| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp // nolint:dupl |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func testParamForwardTSNSupported() []byte { |
| 13 |
return []byte{0xc0, 0x0, 0x0, 0x4} |
| 14 |
} |
| 15 |
|
| 16 |
func TestParamForwardTSNSupported_Success(t *testing.T) { |
| 17 |
tt := []struct { |
| 18 |
binary []byte |
| 19 |
parsed *paramForwardTSNSupported |
| 20 |
}{ |
| 21 |
{ |
| 22 |
testParamForwardTSNSupported(), |
| 23 |
¶mForwardTSNSupported{ |
| 24 |
paramHeader: paramHeader{ |
| 25 |
typ: forwardTSNSupp, |
| 26 |
len: 4, |
| 27 |
unrecognizedAction: paramHeaderUnrecognizedActionSkipAndReport, |
| 28 |
raw: []byte{}, |
| 29 |
}, |
| 30 |
}, |
| 31 |
}, |
| 32 |
} |
| 33 |
|
| 34 |
for i, tc := range tt { |
| 35 |
actual := ¶mForwardTSNSupported{} |
| 36 |
_, err := actual.unmarshal(tc.binary) |
| 37 |
assert.NoErrorf(t, err, "failed to unmarshal #%d", i) |
| 38 |
assert.Equal(t, tc.parsed, actual) |
| 39 |
|
| 40 |
b, err := actual.marshal() |
| 41 |
assert.NoErrorf(t, err, "failed to unmarshal #%d", i) |
| 42 |
assert.Equal(t, tc.binary, b) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func TestParamForwardTSNSupported_Failure(t *testing.T) { |
| 47 |
tt := []struct { |
| 48 |
name string |
| 49 |
binary []byte |
| 50 |
}{ |
| 51 |
{"param too short", []byte{0x0, 0xd, 0x0}}, |
| 52 |
} |
| 53 |
|
| 54 |
for i, tc := range tt { |
| 55 |
actual := ¶mForwardTSNSupported{} |
| 56 |
_, err := actual.unmarshal(tc.binary) |
| 57 |
assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name) |
| 58 |
} |
| 59 |
} |