@@ -6,140 +6,114 @@ import (
66 "testing"
77 "time"
88
9- "github.com/stretchr/testify/assert"
10- "github.com/stretchr/testify/suite"
9+ "github.com/stretchr/testify/require"
1110 "github.com/zencoder/go-dash/helpers/testfixtures"
1211)
1312
14- type MPDReadWriteSuite struct {
15- suite.Suite
13+ func TestReadingManifests (t * testing.T ) {
14+ var testCases = []struct {
15+ err , filepath string
16+ }{
17+ {filepath : "fixtures/live_profile.mpd" , err : "" },
18+ {filepath : "fixtures/ondemand_profile.mpd" , err : "" },
19+ {filepath : "fixtures/invalid.mpd" , err : "XML syntax error on line 3: unexpected EOF" },
20+ {filepath : "doesntexist.mpd" , err : "open doesntexist.mpd: no such file or directory" },
21+ }
22+
23+ for _ , tc := range testCases {
24+ // Test reading from manifest files
25+ if m , err := ReadFromFile (tc .filepath ); tc .err == "" {
26+ require .NoError (t , err , "Error while reading " + tc .filepath )
27+ require .NotNil (t , m , "Empty result from reading " + tc .filepath )
28+ } else {
29+ require .EqualError (t , err , tc .err )
30+ }
31+
32+ // Test reading valid files from strings
33+ if tc .err == "" {
34+ xmlStr := testfixtures .LoadFixture (tc .filepath )
35+ _ , err := ReadFromString (xmlStr )
36+ require .NotNil (t , xmlStr )
37+ require .NoError (t , err )
38+ }
39+ }
1640}
1741
18- func TestMPDReadWriteSuite (t * testing.T ) {
19- suite .Run (t , new (MPDReadWriteSuite ))
20- }
21-
22- func (s * MPDReadWriteSuite ) SetupTest () {
23-
24- }
25-
26- func (s * MPDReadWriteSuite ) SetupSuite () {
27-
28- }
29-
30- func (s * MPDReadWriteSuite ) TestReadFromFileLiveProfile () {
31- m , err := ReadFromFile ("fixtures/live_profile.mpd" )
32- assert .NotNil (s .T (), m )
33- assert .Nil (s .T (), err )
34- }
35-
36- func (s * MPDReadWriteSuite ) TestReadFromFileOnDemandProfile () {
37- m , err := ReadFromFile ("fixtures/ondemand_profile.mpd" )
38- assert .NotNil (s .T (), m )
39- assert .Nil (s .T (), err )
40- }
41-
42- func (s * MPDReadWriteSuite ) TestReadFromFileErrorInvalidMPD () {
43- m , err := ReadFromFile ("fixtures/invalid.mpd" )
44- assert .Nil (s .T (), m )
45- assert .NotNil (s .T (), err )
46- }
47-
48- func (s * MPDReadWriteSuite ) TestReadFromFileErrorInvalidFilePath () {
49- m , err := ReadFromFile ("this is an invalid file path" )
50- assert .Nil (s .T (), m )
51- assert .NotNil (s .T (), err )
52- }
53-
54- func (s * MPDReadWriteSuite ) TestReadFromStringLiveProfile () {
55- xmlStr := testfixtures .LoadFixture ("fixtures/live_profile.mpd" )
56- m , err := ReadFromString (xmlStr )
57- assert .NotNil (s .T (), m )
58- assert .Nil (s .T (), err )
59- }
60-
61- func (s * MPDReadWriteSuite ) TestReadFromStringOnDemandProfile () {
62- xmlStr := testfixtures .LoadFixture ("fixtures/ondemand_profile.mpd" )
63- m , err := ReadFromString (xmlStr )
64- assert .NotNil (s .T (), m )
65- assert .Nil (s .T (), err )
66- }
67-
68- func (s * MPDReadWriteSuite ) TestNewMPDLiveWriteToString () {
42+ func TestNewMPDLiveWriteToString (t * testing.T ) {
6943 m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
7044
7145 xmlStr , err := m .WriteToString ()
72- assert .Nil (s . T () , err )
46+ require .Nil (t , err )
7347 expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
7448<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
7549 <Period></Period>
7650</MPD>
7751`
78- assert .Equal (s . T () , expectedXML , xmlStr )
52+ require .Equal (t , expectedXML , xmlStr )
7953}
8054
81- func ( s * MPDReadWriteSuite ) TestNewMPDOnDemandWriteToString ( ) {
55+ func TestNewMPDOnDemandWriteToString ( t * testing. T ) {
8256 m := NewMPD (DASH_PROFILE_ONDEMAND , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
8357
8458 xmlStr , err := m .WriteToString ()
85- assert .Nil (s . T () , err )
59+ require .Nil (t , err )
8660 expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
8761<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
8862 <Period></Period>
8963</MPD>
9064`
91- assert .Equal (s . T () , expectedXML , xmlStr )
65+ require .Equal (t , expectedXML , xmlStr )
9266}
9367
94- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetAudioWriteToString ( ) {
68+ func TestAddNewAdaptationSetAudioWriteToString ( t * testing. T ) {
9569 m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
9670
9771 m .AddNewAdaptationSetAudio (DASH_MIME_TYPE_AUDIO_MP4 , VALID_SEGMENT_ALIGNMENT , VALID_START_WITH_SAP , VALID_LANG )
9872
9973 xmlStr , err := m .WriteToString ()
100- assert .Nil (s . T () , err )
74+ require .Nil (t , err )
10175 expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
10276<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
10377 <Period>
10478 <AdaptationSet mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="en"></AdaptationSet>
10579 </Period>
10680</MPD>
10781`
108- assert .Equal (s . T () , expectedXML , xmlStr )
82+ require .Equal (t , expectedXML , xmlStr )
10983}
11084
111- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetVideoWriteToString ( ) {
85+ func TestAddNewAdaptationSetVideoWriteToString ( t * testing. T ) {
11286 m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
11387
11488 m .AddNewAdaptationSetVideo (DASH_MIME_TYPE_VIDEO_MP4 , VALID_SCAN_TYPE , VALID_SEGMENT_ALIGNMENT , VALID_START_WITH_SAP )
11589
11690 xmlStr , err := m .WriteToString ()
117- assert .Nil (s . T () , err )
91+ require .Nil (t , err )
11892 expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
11993<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
12094 <Period>
12195 <AdaptationSet mimeType="video/mp4" scanType="progressive" segmentAlignment="true" startWithSAP="1"></AdaptationSet>
12296 </Period>
12397</MPD>
12498`
125- assert .Equal (s . T () , expectedXML , xmlStr )
99+ require .Equal (t , expectedXML , xmlStr )
126100}
127101
128- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetSubtitleWriteToString ( ) {
102+ func TestAddNewAdaptationSetSubtitleWriteToString ( t * testing. T ) {
129103 m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
130104
131105 m .AddNewAdaptationSetSubtitle (DASH_MIME_TYPE_SUBTITLE_VTT , VALID_LANG )
132106
133107 xmlStr , err := m .WriteToString ()
134- assert .Nil (s . T () , err )
108+ require .Nil (t , err )
135109 expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
136110<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
137111 <Period>
138112 <AdaptationSet mimeType="text/vtt" lang="en"></AdaptationSet>
139113 </Period>
140114</MPD>
141115`
142- assert .Equal (s . T () , expectedXML , xmlStr )
116+ require .Equal (t , expectedXML , xmlStr )
143117}
144118
145119func ExampleAddNewPeriod () {
@@ -223,21 +197,21 @@ func LiveProfile() *MPD {
223197 return m
224198}
225199
226- func ( s * MPDReadWriteSuite ) TestFullLiveProfileWriteToString ( ) {
200+ func TestFullLiveProfileWriteToString ( t * testing. T ) {
227201 m := LiveProfile ()
228- assert .NotNil (s . T () , m )
202+ require .NotNil (t , m )
229203 xmlStr , err := m .WriteToString ()
230- assert .Nil (s . T () , err )
204+ require .Nil (t , err )
231205 expectedXML := testfixtures .LoadFixture ("fixtures/live_profile.mpd" )
232- assert .Equal (s . T () , expectedXML , xmlStr )
206+ require .Equal (t , expectedXML , xmlStr )
233207}
234208
235- func ( s * MPDReadWriteSuite ) TestFullLiveProfileWriteToFile ( ) {
209+ func TestFullLiveProfileWriteToFile ( t * testing. T ) {
236210 m := LiveProfile ()
237- assert .NotNil (s . T () , m )
211+ require .NotNil (t , m )
238212 err := m .WriteToFile ("test_live.mpd" )
239213 defer os .Remove ("test_live.mpd" )
240- assert .Nil (s . T () , err )
214+ require .Nil (t , err )
241215}
242216
243217func HbbTVProfile () * MPD {
@@ -276,21 +250,21 @@ func HbbTVProfile() *MPD {
276250 return m
277251}
278252
279- func ( s * MPDReadWriteSuite ) TestFullHbbTVProfileWriteToString ( ) {
253+ func TestFullHbbTVProfileWriteToString ( t * testing. T ) {
280254 m := HbbTVProfile ()
281- assert .NotNil (s . T () , m )
255+ require .NotNil (t , m )
282256 xmlStr , err := m .WriteToString ()
283- assert .Nil (s . T () , err )
257+ require .Nil (t , err )
284258 expectedXML := testfixtures .LoadFixture ("fixtures/hbbtv_profile.mpd" )
285- assert .Equal (s . T () , expectedXML , xmlStr )
259+ require .Equal (t , expectedXML , xmlStr )
286260}
287261
288- func ( s * MPDReadWriteSuite ) TestFullHbbTVProfileWriteToFile ( ) {
262+ func TestFullHbbTVProfileWriteToFile ( t * testing. T ) {
289263 m := HbbTVProfile ()
290- assert .NotNil (s . T () , m )
264+ require .NotNil (t , m )
291265 err := m .WriteToFile ("test_hbbtv.mpd" )
292266 defer os .Remove ("test_hbbtv.mpd" )
293- assert .Nil (s . T () , err )
267+ require .Nil (t , err )
294268}
295269
296270func OnDemandProfile () * MPD {
@@ -327,26 +301,26 @@ func OnDemandProfile() *MPD {
327301 return m
328302}
329303
330- func ( s * MPDReadWriteSuite ) TestFullOnDemandProfileWriteToString ( ) {
304+ func TestFullOnDemandProfileWriteToString ( t * testing. T ) {
331305 m := OnDemandProfile ()
332- assert .NotNil (s . T () , m )
306+ require .NotNil (t , m )
333307 xmlStr , err := m .WriteToString ()
334- assert .Nil (s . T () , err )
308+ require .Nil (t , err )
335309 expectedXML := testfixtures .LoadFixture ("fixtures/ondemand_profile.mpd" )
336- assert .Equal (s . T () , expectedXML , xmlStr )
310+ require .Equal (t , expectedXML , xmlStr )
337311}
338312
339- func ( s * MPDReadWriteSuite ) TestFullOnDemandProfileWriteToFile ( ) {
313+ func TestFullOnDemandProfileWriteToFile ( t * testing. T ) {
340314 m := OnDemandProfile ()
341- assert .NotNil (s . T () , m )
315+ require .NotNil (t , m )
342316 err := m .WriteToFile ("test-ondemand.mpd" )
343317 defer os .Remove ("test-ondemand.mpd" )
344- assert .Nil (s . T () , err )
318+ require .Nil (t , err )
345319}
346320
347- func ( s * MPDReadWriteSuite ) TestWriteToFileInvalidFilePath ( ) {
321+ func TestWriteToFileInvalidFilePath ( t * testing. T ) {
348322 m := LiveProfile ()
349- assert .NotNil (s . T () , m )
323+ require .NotNil (t , m )
350324 err := m .WriteToFile ("" )
351- assert .NotNil (s . T () , err )
325+ require .NotNil (t , err )
352326}
0 commit comments