forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream_handler_test.go
59 lines (47 loc) · 2.29 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/assert"
)
func TestStreamHandlerChangeState(t *testing.T) {
rwc := &rwcMock{}
c := newConn(rwc, nil)
s := newStream(42, c)
s.handler.ChangeState(streamStateUnknown)
assert.Equal(t, s.handler.state, streamStateUnknown)
assert.Equal(t, s.handler.handler, nil)
s.handler.ChangeState(streamStateServerNotConnected)
assert.Equal(t, s.handler.state, streamStateServerNotConnected)
assert.Equal(t, s.handler.handler, &serverControlNotConnectedHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerConnected)
assert.Equal(t, s.handler.state, streamStateServerConnected)
assert.Equal(t, s.handler.handler, &serverControlConnectedHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerInactive)
assert.Equal(t, s.handler.state, streamStateServerInactive)
assert.Equal(t, s.handler.handler, &serverDataInactiveHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerPublish)
assert.Equal(t, s.handler.state, streamStateServerPublish)
assert.Equal(t, s.handler.handler, &serverDataPublishHandler{sh: s.handler})
s.handler.ChangeState(streamStateServerPlay)
assert.Equal(t, s.handler.state, streamStateServerPlay)
assert.Equal(t, s.handler.handler, &serverDataPlayHandler{sh: s.handler})
s.handler.ChangeState(streamStateClientNotConnected)
assert.Equal(t, s.handler.state, streamStateClientNotConnected)
assert.Equal(t, s.handler.handler, &clientControlNotConnectedHandler{sh: s.handler})
}
func TestStreamStateString(t *testing.T) {
assert.Equal(t, "<Unknown>", streamStateUnknown.String())
assert.Equal(t, "NotConnected(Server)", streamStateServerNotConnected.String())
assert.Equal(t, "Connected(Server)", streamStateServerConnected.String())
assert.Equal(t, "Inactive(Server)", streamStateServerInactive.String())
assert.Equal(t, "Publish(Server)", streamStateServerPublish.String())
assert.Equal(t, "Play(Server)", streamStateServerPlay.String())
assert.Equal(t, "NotConnected(Client)", streamStateClientNotConnected.String())
assert.Equal(t, "Connected(Client)", streamStateClientConnected.String())
}