mirror of
https://github.com/pion/webrtc.git
synced 2025-10-07 08:01:27 +08:00
36 lines
1.6 KiB
Go
36 lines
1.6 KiB
Go
package webrtc
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateDataChannelID(t *testing.T) {
|
|
testCases := []struct {
|
|
client bool
|
|
c *RTCPeerConnection
|
|
result uint16
|
|
}{
|
|
{true, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{}}, 0},
|
|
{true, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{1: nil}}, 0},
|
|
{true, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{0: nil}}, 2},
|
|
{true, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{0: nil, 2: nil}}, 4},
|
|
{true, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{0: nil, 4: nil}}, 2},
|
|
{false, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{}}, 1},
|
|
{false, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{0: nil}}, 1},
|
|
{false, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{1: nil}}, 3},
|
|
{false, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{1: nil, 3: nil}}, 5},
|
|
{false, &RTCPeerConnection{sctp: newRTCSctpTransport(), dataChannels: map[uint16]*RTCDataChannel{1: nil, 5: nil}}, 3},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
id, err := testCase.c.generateDataChannelID(testCase.client)
|
|
if err != nil {
|
|
t.Errorf("failed to generate id: %v", err)
|
|
return
|
|
}
|
|
if id != testCase.result {
|
|
t.Errorf("Wrong id: %d expected %d", id, testCase.result)
|
|
}
|
|
}
|
|
}
|