forked from edgeware/mpd
/
mpd_test.go
120 lines (99 loc) · 3.9 KB
/
mpd_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package mpd
import (
"io/ioutil"
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/require"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type MPDSuite struct{}
var _ = Suite(&MPDSuite{})
func testUnmarshalMarshal(c *C, name string) {
expected, err := ioutil.ReadFile(name)
c.Assert(err, IsNil)
mpd := new(MPD)
err = mpd.Decode(expected)
c.Assert(err, IsNil)
obtained, err := mpd.Encode()
c.Assert(err, IsNil)
obtainedName := name + ".ignore"
err = ioutil.WriteFile(obtainedName, obtained, 0666)
c.Assert(err, IsNil)
// strip stupid XML rubish
expectedS := string(expected)
obtainedSlice := strings.Split(strings.TrimSpace(string(obtained)), "\n")
expectedSlice := strings.Split(strings.TrimSpace(expectedS), "\n")
c.Check(obtainedSlice, HasLen, len(expectedSlice))
for i := range obtainedSlice {
c.Check(obtainedSlice[i], Equals, expectedSlice[i], Commentf("line %d", i+1))
}
}
func (s *MPDSuite) TestUnmarshalMarshalVod(c *C) {
testUnmarshalMarshal(c, "fixture_elemental_delta_vod.mpd")
}
func (s *MPDSuite) TestUnmarshalMarshalLive(c *C) {
testUnmarshalMarshal(c, "fixture_elemental_delta_live.mpd")
}
func (s *MPDSuite) TestUnmarshalMarshalLiveDelta161(c *C) {
testUnmarshalMarshal(c, "fixture_elemental_delta_vod_multi_drm.mpd")
}
func TestMPDEqual(t *testing.T) {
mpd := &MPD{}
mpdM := &mpdMarshal{}
require.Equal(t, 16, reflect.ValueOf(mpd).Elem().NumField(),
"model was updated, need to update this test and function modifyMPD")
require.Equal(t, reflect.ValueOf(mpd).Elem().NumField(), reflect.ValueOf(mpdM).Elem().NumField(),
"MPD element count not equal mpdMarshal")
}
func TestPeriodEqual(t *testing.T) {
mpd := &Period{}
mpdM := &periodMarshal{}
require.Equal(t, 4, reflect.ValueOf(mpd).Elem().NumField(),
"model was updated, need to update this test and function modifyPeriod")
require.Equal(t, reflect.ValueOf(mpd).Elem().NumField(), reflect.ValueOf(mpdM).Elem().NumField(),
"Period element count not equal periodMarshal")
}
func TestAdaptationSetEqual(t *testing.T) {
mpd := &AdaptationSet{}
mpdM := &adaptationSetMarshal{}
require.Equal(t, 9, reflect.ValueOf(mpd).Elem().NumField(),
"model was updated, need to update this test and function modifyAdaptationSets")
require.Equal(t, reflect.ValueOf(mpd).Elem().NumField(), reflect.ValueOf(mpdM).Elem().NumField(),
"AdaptationSet element count not equal adaptationSetMarshal")
}
func TestRepresentationEqual(t *testing.T) {
a := &Representation{}
b := &Representation{}
require.Equal(t, 10, reflect.ValueOf(a).Elem().NumField(),
"model was updated, need to update this test and function modifyRepresentations")
require.Equal(t, reflect.ValueOf(a).Elem().NumField(), reflect.ValueOf(b).Elem().NumField(),
"Representation element count not equal Representation")
}
func TestSegmentTemplateEqual(t *testing.T) {
a := &SegmentTemplate{}
require.Equal(t, 6, reflect.ValueOf(a).Elem().NumField(),
"model was updated, need to update this test and function copySegmentTemplate")
}
func TestSegmentTimelineSEqual(t *testing.T) {
a := &SegmentTimelineS{}
require.Equal(t, 3, reflect.ValueOf(a).Elem().NumField(),
"model was updated, need to update this test and function copySegmentTimelineS")
}
func TestDescriptorEqual(t *testing.T) {
a := &Descriptor{}
b := &descriptorMarshal{}
require.Equal(t, 5, reflect.ValueOf(a).Elem().NumField(),
"model was updated, need to update this test and function modifyContentProtections")
require.Equal(t, reflect.ValueOf(a).Elem().NumField(), reflect.ValueOf(b).Elem().NumField(),
"Descriptor element count not equal descriptorMarshal")
}
func TestPsshEqual(t *testing.T) {
a := &Pssh{}
b := &psshMarshal{}
require.Equal(t, 2, reflect.ValueOf(a).Elem().NumField(),
"model was updated, need to update this test and function modifyPssh")
require.Equal(t, reflect.ValueOf(a).Elem().NumField(), reflect.ValueOf(b).Elem().NumField(),
"Pssh element count not equal psshMarshal")
}