@@ -20,7 +20,6 @@ import (
20
20
"encoding/binary"
21
21
"encoding/json"
22
22
"encoding/xml"
23
- "fmt"
24
23
"io"
25
24
"os"
26
25
"testing"
@@ -30,6 +29,11 @@ import (
30
29
"github.com/stretchr/testify/require"
31
30
)
32
31
32
+ func TestMain (m * testing.M ) {
33
+ scte35 .Logger .SetOutput (os .Stderr )
34
+ os .Exit (m .Run ())
35
+ }
36
+
33
37
func TestDecodeBase64 (t * testing.T ) {
34
38
scte35 .Logger .SetOutput (os .Stderr )
35
39
defer scte35 .Logger .SetOutput (io .Discard )
@@ -63,7 +67,7 @@ func TestDecodeBase64(t *testing.T) {
63
67
SegmentationTypeID : scte35 .SegmentationTypeProviderPOStart ,
64
68
SegmentationDuration : uint64ptr (0x0001a599b0 ),
65
69
SegmentationUPIDs : []scte35.SegmentationUPID {
66
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca0a18a )),
70
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca0a18a )),
67
71
},
68
72
SegmentNum : 2 ,
69
73
},
@@ -118,7 +122,7 @@ func TestDecodeBase64(t *testing.T) {
118
122
SegmentationEventID : 0x4800008e ,
119
123
SegmentationTypeID : scte35 .SegmentationTypeProviderPOEnd ,
120
124
SegmentationUPIDs : []scte35.SegmentationUPID {
121
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca0a18a )),
125
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca0a18a )),
122
126
},
123
127
SegmentNum : 2 ,
124
128
},
@@ -147,7 +151,7 @@ func TestDecodeBase64(t *testing.T) {
147
151
SegmentationEventID : 0x48000018 ,
148
152
SegmentationTypeID : scte35 .SegmentationTypeProgramEnd ,
149
153
SegmentationUPIDs : []scte35.SegmentationUPID {
150
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ccbc344 )),
154
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ccbc344 )),
151
155
},
152
156
},
153
157
& scte35.SegmentationDescriptor {
@@ -160,7 +164,7 @@ func TestDecodeBase64(t *testing.T) {
160
164
SegmentationEventID : 0x48000019 ,
161
165
SegmentationTypeID : scte35 .SegmentationTypeProgramStart ,
162
166
SegmentationUPIDs : []scte35.SegmentationUPID {
163
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca4dba0 )),
167
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca4dba0 )),
164
168
},
165
169
},
166
170
},
@@ -188,7 +192,7 @@ func TestDecodeBase64(t *testing.T) {
188
192
SegmentationEventID : 0x48000008 ,
189
193
SegmentationTypeID : scte35 .SegmentationTypeProgramOverlapStart ,
190
194
SegmentationUPIDs : []scte35.SegmentationUPID {
191
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca56cf5 )),
195
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca56cf5 )),
192
196
},
193
197
},
194
198
},
@@ -216,7 +220,7 @@ func TestDecodeBase64(t *testing.T) {
216
220
SegmentationEventID : 0x4800000a ,
217
221
SegmentationTypeID : scte35 .SegmentationTypeProgramBlackoutOverride ,
218
222
SegmentationUPIDs : []scte35.SegmentationUPID {
219
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca0a1e3 )),
223
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca0a1e3 )),
220
224
},
221
225
},
222
226
& scte35.SegmentationDescriptor {
@@ -229,7 +233,7 @@ func TestDecodeBase64(t *testing.T) {
229
233
SegmentationEventID : 0x48000009 ,
230
234
SegmentationTypeID : scte35 .SegmentationTypeProgramEnd ,
231
235
SegmentationUPIDs : []scte35.SegmentationUPID {
232
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca0a18a )),
236
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca0a18a )),
233
237
},
234
238
},
235
239
},
@@ -257,7 +261,7 @@ func TestDecodeBase64(t *testing.T) {
257
261
SegmentationEventID : 0x48000007 ,
258
262
SegmentationTypeID : scte35 .SegmentationTypeProgramEnd ,
259
263
SegmentationUPIDs : []scte35.SegmentationUPID {
260
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca56c97 )),
264
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca56c97 )),
261
265
},
262
266
},
263
267
},
@@ -285,7 +289,7 @@ func TestDecodeBase64(t *testing.T) {
285
289
SegmentationEventID : 0x480000ad ,
286
290
SegmentationTypeID : scte35 .SegmentationTypeProviderPOEnd ,
287
291
SegmentationUPIDs : []scte35.SegmentationUPID {
288
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002cb2d79d )),
292
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002cb2d79d )),
289
293
},
290
294
SegmentNum : 2 ,
291
295
},
@@ -299,7 +303,7 @@ func TestDecodeBase64(t *testing.T) {
299
303
SegmentationEventID : 0x48000026 ,
300
304
SegmentationTypeID : scte35 .SegmentationTypeProgramEnd ,
301
305
SegmentationUPIDs : []scte35.SegmentationUPID {
302
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002cb2d79d )),
306
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002cb2d79d )),
303
307
},
304
308
},
305
309
& scte35.SegmentationDescriptor {
@@ -312,7 +316,7 @@ func TestDecodeBase64(t *testing.T) {
312
316
SegmentationEventID : 0x48000027 ,
313
317
SegmentationTypeID : scte35 .SegmentationTypeProgramStart ,
314
318
SegmentationUPIDs : []scte35.SegmentationUPID {
315
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002cb2d7b3 )),
319
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002cb2d7b3 )),
316
320
},
317
321
},
318
322
},
@@ -388,7 +392,7 @@ func TestDecodeBase64(t *testing.T) {
388
392
},
389
393
"Empty String" : {
390
394
binary : "" ,
391
- err : fmt . Errorf ( "splice_info_section: %w" , scte35 .ErrBufferOverflow ) ,
395
+ err : scte35 .ErrBufferOverflow ,
392
396
},
393
397
"Invalid Base64 Encoding" : {
394
398
binary : "/DBaf%^" ,
@@ -468,7 +472,7 @@ func TestDecodeBase64(t *testing.T) {
468
472
},
469
473
"SpliceInsert Time Specified With Invalid Component Count" : {
470
474
binary : "FkC1lwP3uTQD0VvxHwVBEH89G6B7VjzaZ9eNuyUF9q8pYAIXsRM9ZpDCczBeDbytQhXkssQstGJVGcvjZ3tiIMULiA4BpRHlzLGFa0q6aVMtzk8ZRUeLcxtKibgVOKBBnkCbOQyhSflFiDkrAAIp+Fk+VRsByTSkPN3RvyK+lWcjHElhwa9hNFcAy4dm3DdeRXnrD3I2mISNc7DkgS0ReotPyp94FV77xMHT4D7SYL48XU20UM4bgg==" ,
471
- err : fmt . Errorf ( "splice_insert: %w" , scte35 .ErrBufferOverflow ) ,
475
+ err : scte35 .ErrBufferOverflow ,
472
476
},
473
477
"Signal with non-CUEI descriptor" : {
474
478
binary : "/DBPAAAAAAAAAP/wBQb/Gq9LggA5AAVTQVBTCwIwQ1VFSf////9//wAAFI4PDxx1cm46bmJjdW5pLmNvbTpicmM6NDk5ODY2NDM0MQoBbM98zw==" ,
@@ -507,7 +511,7 @@ func TestDecodeBase64(t *testing.T) {
507
511
},
508
512
"Invalid CRC_32" : {
509
513
binary : "/DA4AAAAAAAAAP/wFAUABDEAf+//mWEhzP4Azf5gAQAAAAATAhFDVUVJAAAAAX+/AQIwNAEAAKeYO3Q=" ,
510
- err : fmt . Errorf ( "splice_info_section: %w" , scte35 .ErrCRC32Invalid ) ,
514
+ err : scte35 .ErrCRC32Invalid ,
511
515
},
512
516
"Alignment Stuffing without Encryption" : {
513
517
binary : "/DAeAAAAAAAAAP///wViAA/nf18ACQAAAAAskJv+YPtE" ,
@@ -523,13 +527,103 @@ func TestDecodeBase64(t *testing.T) {
523
527
},
524
528
legacy : true , // binary wont match because of stuffing
525
529
},
530
+ "UPID with Valid ASCII Invalid UTF8" : {
531
+ binary : "/DDHAAAAABc0AP/wBQb/tVo+agCxAhdDVUVJQA4hwH+fCAgAAAAAPj6IcCMAAAIXQ1VFSUAOI1x/nwgIAAAAAD4+iHARAAACF0NVRUlADiHgf58ICAAAAAA+Poi2EAAAAhxDVUVJQA4hyn/fAABSlKwICAAAAAA+Poi2IgAAAkZDVUVJQA4h1n/PAABSlKwNMgoMFHf5uXs0AAAAAAAADhh0eXBlPUxBJmR1cj02MDAwMCZ0aWVy/DDHAAAAAAAAAP8ABQb/HPCt2w==" ,
532
+ expected : scte35.SpliceInfoSection {
533
+ SpliceCommand : & scte35.TimeSignal {
534
+ SpliceTime : scte35.SpliceTime {
535
+ PTSTime : uint64ptr (7337557610 ),
536
+ },
537
+ },
538
+ SpliceDescriptors : scte35.SpliceDescriptors {
539
+ & scte35.SegmentationDescriptor {
540
+ SegmentationEventID : uint32 (1074667968 ),
541
+ SegmentationTypeID : scte35 .SegmentationTypeBreakEnd ,
542
+ DeliveryRestrictions : & scte35.DeliveryRestrictions {
543
+ ArchiveAllowedFlag : true ,
544
+ WebDeliveryAllowedFlag : true ,
545
+ NoRegionalBlackoutFlag : true ,
546
+ DeviceRestrictions : 3 ,
547
+ },
548
+ SegmentationUPIDs : []scte35.SegmentationUPID {
549
+ {Type : scte35 .SegmentationUPIDTypeTI , Value : "1044285552" },
550
+ },
551
+ },
552
+ & scte35.SegmentationDescriptor {
553
+ SegmentationEventID : uint32 (1074668380 ),
554
+ SegmentationTypeID : scte35 .SegmentationTypeProgramEnd ,
555
+ DeliveryRestrictions : & scte35.DeliveryRestrictions {
556
+ ArchiveAllowedFlag : true ,
557
+ WebDeliveryAllowedFlag : true ,
558
+ NoRegionalBlackoutFlag : true ,
559
+ DeviceRestrictions : 3 ,
560
+ },
561
+ SegmentationUPIDs : []scte35.SegmentationUPID {
562
+ {Type : scte35 .SegmentationUPIDTypeTI , Value : "1044285552" },
563
+ },
564
+ },
565
+ & scte35.SegmentationDescriptor {
566
+ SegmentationEventID : uint32 (1074668000 ),
567
+ SegmentationTypeID : scte35 .SegmentationTypeProgramStart ,
568
+ DeliveryRestrictions : & scte35.DeliveryRestrictions {
569
+ ArchiveAllowedFlag : true ,
570
+ WebDeliveryAllowedFlag : true ,
571
+ NoRegionalBlackoutFlag : true ,
572
+ DeviceRestrictions : 3 ,
573
+ },
574
+ SegmentationUPIDs : []scte35.SegmentationUPID {
575
+ {Type : scte35 .SegmentationUPIDTypeTI , Value : "1044285622" },
576
+ },
577
+ },
578
+ & scte35.SegmentationDescriptor {
579
+ SegmentationEventID : uint32 (1074667978 ),
580
+ SegmentationDuration : uint64ptr (5412012 ),
581
+ SegmentationTypeID : scte35 .SegmentationTypeBreakStart ,
582
+ DeliveryRestrictions : & scte35.DeliveryRestrictions {
583
+ ArchiveAllowedFlag : true ,
584
+ WebDeliveryAllowedFlag : true ,
585
+ NoRegionalBlackoutFlag : true ,
586
+ DeviceRestrictions : 3 ,
587
+ },
588
+ SegmentationUPIDs : []scte35.SegmentationUPID {
589
+ {Type : scte35 .SegmentationUPIDTypeTI , Value : "1044285622" },
590
+ },
591
+ },
592
+ & scte35.SegmentationDescriptor {
593
+ SegmentationEventID : uint32 (1074667990 ),
594
+ SegmentationTypeID : 0x05 ,
595
+ SegmentationDuration : uint64ptr (5412012 ),
596
+ SegmentNum : 6 ,
597
+ SegmentsExpected : 255 ,
598
+ DeliveryRestrictions : & scte35.DeliveryRestrictions {
599
+ ArchiveAllowedFlag : true ,
600
+ WebDeliveryAllowedFlag : false ,
601
+ NoRegionalBlackoutFlag : true ,
602
+ DeviceRestrictions : 3 ,
603
+ },
604
+ SegmentationUPIDs : []scte35.SegmentationUPID {
605
+ {Type : scte35 .SegmentationUPIDTypeEIDR , Value : "10.5239/F9B9-7B34-0000-0000-0000" },
606
+ {Type : scte35 .SegmentationUPIDTypeADS , Value : "type=LA&dur=60000&tierü0" },
607
+ {Type : uint32 (199 )},
608
+ {Type : uint32 (0 )},
609
+ {Type : uint32 (0 )},
610
+ {Type : uint32 (0 )},
611
+ {Type : uint32 (255 )},
612
+ },
613
+ },
614
+ },
615
+ PTSAdjustment : uint64 (5940 ),
616
+ Tier : 4095 ,
617
+ SAPType : 3 ,
618
+ },
619
+ },
526
620
}
527
621
528
622
for k , c := range cases {
529
623
t .Run (k , func (t * testing.T ) {
530
624
// decode the binary
531
625
sis , err := scte35 .DecodeBase64 (c .binary )
532
- require .Equal (t , c . err , err )
626
+ require .ErrorIs (t , err , c . err )
533
627
if err != nil {
534
628
return
535
629
}
@@ -591,7 +685,7 @@ func TestDecodeHex(t *testing.T) {
591
685
SegmentationTypeID : scte35 .SegmentationTypeProviderPOStart ,
592
686
SegmentationDuration : uint64ptr (0x0001a599b0 ),
593
687
SegmentationUPIDs : []scte35.SegmentationUPID {
594
- scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , bytes (0x000000002ca0a18a )),
688
+ scte35 .NewSegmentationUPID (scte35 .SegmentationUPIDTypeTI , toBytes (0x000000002ca0a18a )),
595
689
},
596
690
SegmentNum : 2 ,
597
691
},
@@ -686,7 +780,7 @@ func TestTicksToDuration(t *testing.T) {
686
780
687
781
// helper func to make test life a bit easier
688
782
689
- func bytes (i uint64 ) []byte {
783
+ func toBytes (i uint64 ) []byte {
690
784
b := make ([]byte , 8 )
691
785
binary .BigEndian .PutUint64 (b , i )
692
786
return b
0 commit comments