forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stream_handler_test.go
59 lines (47 loc) · 2.31 KB
/
stream_handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Copyright (c) 2018- yutopp ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//
package rtmp
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestStreamHandlerChangeState(t *testing.T) {
rwc := &rwcMock{}
c := newConn(rwc, nil)
s := newStream(42, c)
s.handler.ChangeState(streamStateUnknown)
require.Equal(t, s.handler.state, streamStateUnknown)
require.Equal(t, s.handler.handler, nil)
s.handler.ChangeState(streamStateServerNotConnected)
require.Equal(t, s.handler.state, streamStateServerNotConnected)
require.Equal(t, s.handler.handler, &serverControlNotConnectedHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerConnected)
require.Equal(t, s.handler.state, streamStateServerConnected)
require.Equal(t, s.handler.handler, &serverControlConnectedHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerInactive)
require.Equal(t, s.handler.state, streamStateServerInactive)
require.Equal(t, s.handler.handler, &serverDataInactiveHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerPublish)
require.Equal(t, s.handler.state, streamStateServerPublish)
require.Equal(t, s.handler.handler, &serverDataPublishHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerPlay)
require.Equal(t, s.handler.state, streamStateServerPlay)
require.Equal(t, s.handler.handler, &serverDataPlayHandler{sh: s.handler})
s.handler.ChangeState(streamStateClientNotConnected)
require.Equal(t, s.handler.state, streamStateClientNotConnected)
require.Equal(t, s.handler.handler, &clientControlNotConnectedHandler{sh: s.handler})
}
func TestStreamStateString(t *testing.T) {
require.Equal(t, "<Unknown>", streamStateUnknown.String())
require.Equal(t, "NotConnected(Server)", streamStateServerNotConnected.String())
require.Equal(t, "Connected(Server)", streamStateServerConnected.String())
require.Equal(t, "Inactive(Server)", streamStateServerInactive.String())
require.Equal(t, "Publish(Server)", streamStateServerPublish.String())
require.Equal(t, "Play(Server)", streamStateServerPlay.String())
require.Equal(t, "NotConnected(Client)", streamStateClientNotConnected.String())
require.Equal(t, "Connected(Client)", streamStateClientConnected.String())
}