Files
webrtc/sctptransport_test.go
Sean DuBois 157220e800 Run gofmt to add new build constraints
Also remove some 1.13 specific WASM code
2022-01-17 22:36:01 -05:00

48 lines
1.4 KiB
Go

//go:build !js
// +build !js
package webrtc
import "testing"
func TestGenerateDataChannelID(t *testing.T) {
sctpTransportWithChannels := func(ids []uint16) *SCTPTransport {
ret := &SCTPTransport{dataChannels: []*DataChannel{}}
for i := range ids {
id := ids[i]
ret.dataChannels = append(ret.dataChannels, &DataChannel{id: &id})
}
return ret
}
testCases := []struct {
role DTLSRole
s *SCTPTransport
result uint16
}{
{DTLSRoleClient, sctpTransportWithChannels([]uint16{}), 0},
{DTLSRoleClient, sctpTransportWithChannels([]uint16{1}), 0},
{DTLSRoleClient, sctpTransportWithChannels([]uint16{0}), 2},
{DTLSRoleClient, sctpTransportWithChannels([]uint16{0, 2}), 4},
{DTLSRoleClient, sctpTransportWithChannels([]uint16{0, 4}), 2},
{DTLSRoleServer, sctpTransportWithChannels([]uint16{}), 1},
{DTLSRoleServer, sctpTransportWithChannels([]uint16{0}), 1},
{DTLSRoleServer, sctpTransportWithChannels([]uint16{1}), 3},
{DTLSRoleServer, sctpTransportWithChannels([]uint16{1, 3}), 5},
{DTLSRoleServer, sctpTransportWithChannels([]uint16{1, 5}), 3},
}
for _, testCase := range testCases {
idPtr := new(uint16)
err := testCase.s.generateAndSetDataChannelID(testCase.role, &idPtr)
if err != nil {
t.Errorf("failed to generate id: %v", err)
return
}
if *idPtr != testCase.result {
t.Errorf("Wrong id: %d expected %d", *idPtr, testCase.result)
}
}
}