forked from mc2soft/mpd
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mpd_test.go
81 lines (59 loc) · 2.3 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
package mpd
import (
"io/ioutil"
"os"
"strings"
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type MPDSuite struct{}
var _ = Suite(&MPDSuite{})
func readFile(c *C, name string) (*MPD, string, 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)
os.Remove(obtainedName)
return mpd, string(expected), string(obtained)
}
func checkLineByLine(c *C, obtained string, expected string) {
obtainedSlice := strings.Split(strings.TrimSpace(obtained), "\n")
expectedSlice := strings.Split(strings.TrimSpace(expected), "\n")
c.Assert(obtainedSlice, HasLen, len(expectedSlice))
for i := range obtainedSlice {
c.Check(obtainedSlice[i], Equals, expectedSlice[i], Commentf("line %d", i+1))
}
}
func testUnmarshalMarshalElemental(c *C, name string) {
_, expected, obtained := readFile(c, name)
// strip stupid XML rubbish
expected = strings.Replace(expected, `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" `, ``, 1)
expected = strings.Replace(expected, `xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" `, ``, 1)
checkLineByLine(c, obtained, expected)
}
func testUnmarshalMarshalAkamai(c *C, name string) {
_, expected, obtained := readFile(c, name)
// strip stupid XML rubbish
expected = strings.Replace(expected, `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" `, ``, 1)
expected = strings.Replace(expected, ` xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd"`, ``, 1)
checkLineByLine(c, obtained, expected)
}
func (s *MPDSuite) TestUnmarshalMarshalVod(c *C) {
testUnmarshalMarshalElemental(c, "fixtures/elemental_delta_vod.mpd")
}
func (s *MPDSuite) TestUnmarshalMarshalLive(c *C) {
testUnmarshalMarshalElemental(c, "fixtures/elemental_delta_live.mpd")
}
func (s *MPDSuite) TestUnmarshalMarshalLiveDelta161(c *C) {
testUnmarshalMarshalElemental(c, "fixtures/elemental_delta_1.6.1_live.mpd")
}
func (s *MPDSuite) TestUnmarshalMarshalSegmentTemplate(c *C) {
testUnmarshalMarshalAkamai(c, "fixtures/akamai_bbb_30fps.mpd")
}