@@ -6,140 +6,114 @@ import (
6
6
"testing"
7
7
"time"
8
8
9
- "github.com/stretchr/testify/assert"
10
- "github.com/stretchr/testify/suite"
9
+ "github.com/stretchr/testify/require"
11
10
"github.com/zencoder/go-dash/helpers/testfixtures"
12
11
)
13
12
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
+ }
16
40
}
17
41
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 ) {
69
43
m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
70
44
71
45
xmlStr , err := m .WriteToString ()
72
- assert .Nil (s . T () , err )
46
+ require .Nil (t , err )
73
47
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
74
48
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
75
49
<Period></Period>
76
50
</MPD>
77
51
`
78
- assert .Equal (s . T () , expectedXML , xmlStr )
52
+ require .Equal (t , expectedXML , xmlStr )
79
53
}
80
54
81
- func ( s * MPDReadWriteSuite ) TestNewMPDOnDemandWriteToString ( ) {
55
+ func TestNewMPDOnDemandWriteToString ( t * testing. T ) {
82
56
m := NewMPD (DASH_PROFILE_ONDEMAND , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
83
57
84
58
xmlStr , err := m .WriteToString ()
85
- assert .Nil (s . T () , err )
59
+ require .Nil (t , err )
86
60
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
87
61
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
88
62
<Period></Period>
89
63
</MPD>
90
64
`
91
- assert .Equal (s . T () , expectedXML , xmlStr )
65
+ require .Equal (t , expectedXML , xmlStr )
92
66
}
93
67
94
- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetAudioWriteToString ( ) {
68
+ func TestAddNewAdaptationSetAudioWriteToString ( t * testing. T ) {
95
69
m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
96
70
97
71
m .AddNewAdaptationSetAudio (DASH_MIME_TYPE_AUDIO_MP4 , VALID_SEGMENT_ALIGNMENT , VALID_START_WITH_SAP , VALID_LANG )
98
72
99
73
xmlStr , err := m .WriteToString ()
100
- assert .Nil (s . T () , err )
74
+ require .Nil (t , err )
101
75
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
102
76
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
103
77
<Period>
104
78
<AdaptationSet mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="en"></AdaptationSet>
105
79
</Period>
106
80
</MPD>
107
81
`
108
- assert .Equal (s . T () , expectedXML , xmlStr )
82
+ require .Equal (t , expectedXML , xmlStr )
109
83
}
110
84
111
- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetVideoWriteToString ( ) {
85
+ func TestAddNewAdaptationSetVideoWriteToString ( t * testing. T ) {
112
86
m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
113
87
114
88
m .AddNewAdaptationSetVideo (DASH_MIME_TYPE_VIDEO_MP4 , VALID_SCAN_TYPE , VALID_SEGMENT_ALIGNMENT , VALID_START_WITH_SAP )
115
89
116
90
xmlStr , err := m .WriteToString ()
117
- assert .Nil (s . T () , err )
91
+ require .Nil (t , err )
118
92
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
119
93
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
120
94
<Period>
121
95
<AdaptationSet mimeType="video/mp4" scanType="progressive" segmentAlignment="true" startWithSAP="1"></AdaptationSet>
122
96
</Period>
123
97
</MPD>
124
98
`
125
- assert .Equal (s . T () , expectedXML , xmlStr )
99
+ require .Equal (t , expectedXML , xmlStr )
126
100
}
127
101
128
- func ( s * MPDReadWriteSuite ) TestAddNewAdaptationSetSubtitleWriteToString ( ) {
102
+ func TestAddNewAdaptationSetSubtitleWriteToString ( t * testing. T ) {
129
103
m := NewMPD (DASH_PROFILE_LIVE , VALID_MEDIA_PRESENTATION_DURATION , VALID_MIN_BUFFER_TIME )
130
104
131
105
m .AddNewAdaptationSetSubtitle (DASH_MIME_TYPE_SUBTITLE_VTT , VALID_LANG )
132
106
133
107
xmlStr , err := m .WriteToString ()
134
- assert .Nil (s . T () , err )
108
+ require .Nil (t , err )
135
109
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
136
110
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
137
111
<Period>
138
112
<AdaptationSet mimeType="text/vtt" lang="en"></AdaptationSet>
139
113
</Period>
140
114
</MPD>
141
115
`
142
- assert .Equal (s . T () , expectedXML , xmlStr )
116
+ require .Equal (t , expectedXML , xmlStr )
143
117
}
144
118
145
119
func ExampleAddNewPeriod () {
@@ -223,21 +197,21 @@ func LiveProfile() *MPD {
223
197
return m
224
198
}
225
199
226
- func ( s * MPDReadWriteSuite ) TestFullLiveProfileWriteToString ( ) {
200
+ func TestFullLiveProfileWriteToString ( t * testing. T ) {
227
201
m := LiveProfile ()
228
- assert .NotNil (s . T () , m )
202
+ require .NotNil (t , m )
229
203
xmlStr , err := m .WriteToString ()
230
- assert .Nil (s . T () , err )
204
+ require .Nil (t , err )
231
205
expectedXML := testfixtures .LoadFixture ("fixtures/live_profile.mpd" )
232
- assert .Equal (s . T () , expectedXML , xmlStr )
206
+ require .Equal (t , expectedXML , xmlStr )
233
207
}
234
208
235
- func ( s * MPDReadWriteSuite ) TestFullLiveProfileWriteToFile ( ) {
209
+ func TestFullLiveProfileWriteToFile ( t * testing. T ) {
236
210
m := LiveProfile ()
237
- assert .NotNil (s . T () , m )
211
+ require .NotNil (t , m )
238
212
err := m .WriteToFile ("test_live.mpd" )
239
213
defer os .Remove ("test_live.mpd" )
240
- assert .Nil (s . T () , err )
214
+ require .Nil (t , err )
241
215
}
242
216
243
217
func HbbTVProfile () * MPD {
@@ -276,21 +250,21 @@ func HbbTVProfile() *MPD {
276
250
return m
277
251
}
278
252
279
- func ( s * MPDReadWriteSuite ) TestFullHbbTVProfileWriteToString ( ) {
253
+ func TestFullHbbTVProfileWriteToString ( t * testing. T ) {
280
254
m := HbbTVProfile ()
281
- assert .NotNil (s . T () , m )
255
+ require .NotNil (t , m )
282
256
xmlStr , err := m .WriteToString ()
283
- assert .Nil (s . T () , err )
257
+ require .Nil (t , err )
284
258
expectedXML := testfixtures .LoadFixture ("fixtures/hbbtv_profile.mpd" )
285
- assert .Equal (s . T () , expectedXML , xmlStr )
259
+ require .Equal (t , expectedXML , xmlStr )
286
260
}
287
261
288
- func ( s * MPDReadWriteSuite ) TestFullHbbTVProfileWriteToFile ( ) {
262
+ func TestFullHbbTVProfileWriteToFile ( t * testing. T ) {
289
263
m := HbbTVProfile ()
290
- assert .NotNil (s . T () , m )
264
+ require .NotNil (t , m )
291
265
err := m .WriteToFile ("test_hbbtv.mpd" )
292
266
defer os .Remove ("test_hbbtv.mpd" )
293
- assert .Nil (s . T () , err )
267
+ require .Nil (t , err )
294
268
}
295
269
296
270
func OnDemandProfile () * MPD {
@@ -327,26 +301,26 @@ func OnDemandProfile() *MPD {
327
301
return m
328
302
}
329
303
330
- func ( s * MPDReadWriteSuite ) TestFullOnDemandProfileWriteToString ( ) {
304
+ func TestFullOnDemandProfileWriteToString ( t * testing. T ) {
331
305
m := OnDemandProfile ()
332
- assert .NotNil (s . T () , m )
306
+ require .NotNil (t , m )
333
307
xmlStr , err := m .WriteToString ()
334
- assert .Nil (s . T () , err )
308
+ require .Nil (t , err )
335
309
expectedXML := testfixtures .LoadFixture ("fixtures/ondemand_profile.mpd" )
336
- assert .Equal (s . T () , expectedXML , xmlStr )
310
+ require .Equal (t , expectedXML , xmlStr )
337
311
}
338
312
339
- func ( s * MPDReadWriteSuite ) TestFullOnDemandProfileWriteToFile ( ) {
313
+ func TestFullOnDemandProfileWriteToFile ( t * testing. T ) {
340
314
m := OnDemandProfile ()
341
- assert .NotNil (s . T () , m )
315
+ require .NotNil (t , m )
342
316
err := m .WriteToFile ("test-ondemand.mpd" )
343
317
defer os .Remove ("test-ondemand.mpd" )
344
- assert .Nil (s . T () , err )
318
+ require .Nil (t , err )
345
319
}
346
320
347
- func ( s * MPDReadWriteSuite ) TestWriteToFileInvalidFilePath ( ) {
321
+ func TestWriteToFileInvalidFilePath ( t * testing. T ) {
348
322
m := LiveProfile ()
349
- assert .NotNil (s . T () , m )
323
+ require .NotNil (t , m )
350
324
err := m .WriteToFile ("" )
351
- assert .NotNil (s . T () , err )
325
+ require .NotNil (t , err )
352
326
}
0 commit comments