| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
) |
| 12 |
|
| 13 |
func TestParseParamType_Success(t *testing.T) { |
| 14 |
tt := []struct { |
| 15 |
binary []byte |
| 16 |
expected paramType |
| 17 |
}{ |
| 18 |
{[]byte{0x0, 0x1}, heartbeatInfo}, |
| 19 |
{[]byte{0x0, 0xd}, outSSNResetReq}, |
| 20 |
} |
| 21 |
|
| 22 |
for i, tc := range tt { |
| 23 |
pType, err := parseParamType(tc.binary) |
| 24 |
assert.NoErrorf(t, err, "failed to parse paramType #%d", i) |
| 25 |
assert.Equal(t, tc.expected, pType) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func TestParseParamType_Failure(t *testing.T) { |
| 30 |
tt := []struct { |
| 31 |
name string |
| 32 |
binary []byte |
| 33 |
}{ |
| 34 |
{"empty packet", []byte{}}, |
| 35 |
} |
| 36 |
|
| 37 |
for i, tc := range tt { |
| 38 |
_, err := parseParamType(tc.binary) |
| 39 |
assert.Errorf(t, err, "expected parseParamType #%d: '%s' to fail.", i, tc.name) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
func TestParamType_String(t *testing.T) { |
| 44 |
tests := []struct { |
| 45 |
name string |
| 46 |
in paramType |
| 47 |
want string |
| 48 |
}{ |
| 49 |
{"heartbeatInfo", heartbeatInfo, "Heartbeat Info"}, |
| 50 |
{"ipV4Addr", ipV4Addr, "IPv4 IP"}, |
| 51 |
{"ipV6Addr", ipV6Addr, "IPv6 IP"}, |
| 52 |
{"stateCookie", stateCookie, "State Cookie"}, |
| 53 |
{"unrecognizedParam", unrecognizedParam, "Unrecognized Parameters"}, |
| 54 |
{"cookiePreservative", cookiePreservative, "Cookie Preservative"}, |
| 55 |
{"hostNameAddr", hostNameAddr, "Host Name Address"}, |
| 56 |
{"supportedAddrTypes", supportedAddrTypes, "Supported IP Types"}, |
| 57 |
{"outSSNResetReq", outSSNResetReq, "Outgoing SSN Reset Request Parameter"}, |
| 58 |
{"incSSNResetReq", incSSNResetReq, "Incoming SSN Reset Request Parameter"}, |
| 59 |
{"ssnTSNResetReq", ssnTSNResetReq, "SSN/TSN Reset Request Parameter"}, |
| 60 |
{"reconfigResp", reconfigResp, "Re-configuration Response Parameter"}, |
| 61 |
{"addOutStreamsReq", addOutStreamsReq, "Add Outgoing Streams Request Parameter"}, |
| 62 |
{"addIncStreamsReq", addIncStreamsReq, "Add Incoming Streams Request Parameter"}, |
| 63 |
{"ecnCapable", ecnCapable, "ECN Capable"}, |
| 64 |
{"zeroChecksumAcceptable", zeroChecksumAcceptable, "Zero Checksum Acceptable"}, |
| 65 |
{"random", random, "Random"}, |
| 66 |
{"chunkList", chunkList, "Chunk List"}, |
| 67 |
{"reqHMACAlgo", reqHMACAlgo, "Requested HMAC Algorithm Parameter"}, |
| 68 |
{"padding", padding, "Padding"}, |
| 69 |
{"supportedExt", supportedExt, "Supported Extensions"}, |
| 70 |
{"forwardTSNSupp", forwardTSNSupp, "Forward TSN supported"}, |
| 71 |
{"addIPAddr", addIPAddr, "Add IP Address"}, |
| 72 |
{"delIPAddr", delIPAddr, "Delete IP Address"}, |
| 73 |
{"errClauseInd", errClauseInd, "Error Cause Indication"}, |
| 74 |
{"setPriAddr", setPriAddr, "Set Primary IP"}, |
| 75 |
{"successInd", successInd, "Success Indication"}, |
| 76 |
{"adaptLayerInd", adaptLayerInd, "Adaptation Layer Indication"}, |
| 77 |
{"unknownValue", paramType(0x4242), fmt.Sprintf("Unknown ParamType: %d", 0x4242)}, |
| 78 |
} |
| 79 |
|
| 80 |
for _, tc := range tests { |
| 81 |
t.Run(tc.name, func(t *testing.T) { |
| 82 |
got := tc.in.String() |
| 83 |
assert.Equal(t, tc.want, got) |
| 84 |
}) |
| 85 |
} |
| 86 |
} |