mirror of
https://github.com/pion/webrtc.git
synced 2025-10-25 00:00:30 +08:00
datachannel: send OpenChannel message
This commit is contained in:
35
rtcdatachannel_test.go
Normal file
35
rtcdatachannel_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user