streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

commit 30cd5b9b300855303d26c8b63ff5c38c291bfce1
parent dfd42b06d7b8816d35e0b574ad54e5146d9d5ab6
Author: Oliver Lowe <o@olowe.co>
Date:   Fri, 10 May 2024 12:18:57 +1000

internal/scte35: create a test table for more scte35 samples

The SCTE 35 spec gives us a range of samples that we will also
(eventually) want to use in our test suite. This makes it easy to add
more tests.

Diffstat:
Minternal/scte35/scte35_test.go | 37+++++++++++++++++++++++++++++++++++++
Minternal/scte35/splice_info_test.go | 72++++++++++++++++++++++++++++++++++--------------------------------------
2 files changed, 71 insertions(+), 38 deletions(-)

diff --git a/internal/scte35/scte35_test.go b/internal/scte35/scte35_test.go @@ -21,6 +21,43 @@ import ( "testing" ) +type sample struct { + name string + encoded string + want SpliceInfo +} + +var samples = []sample{ + { + name: "14.1", + encoded: "/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg==", + want: SpliceInfo{ + SAPType: SAPNone, + Tier: 0x0fff, + Command: &Command{ + Type: TimeSignal, + TimeSignal: newuint64(0x072bd0050), + }, + Descriptors: []SpliceDescriptor{ + SegmentationDescriptor{ + EventID: 0x4800008e, + Restrictions: NoRegionalBlackout | ArchiveAllowed | DeviceRestrictionsNone, + Duration: newuint64(0x0001a599b0), + UPID: UPID{ + Type: UPIDTypeTI, + Value: []byte{0x00, 0x00, 0x00, 0x00, 0x2c, 0xa0, 0xa1, 0x8a}, + }, + Type: 0x34, + Number: 2, + }, + }, + CRC32: 0x9ac9d17e, + }, + }, +} + +func newuint64(i uint64) *uint64 { p := new(uint64); p = &i; return p } + /* func TestDecodeBase64(t *testing.T) { // when adding tests that contain multiple splice descriptors, care must be diff --git a/internal/scte35/splice_info_test.go b/internal/scte35/splice_info_test.go @@ -2,7 +2,6 @@ package scte35 import ( "encoding/base64" - "encoding/binary" "reflect" "testing" ) @@ -16,6 +15,7 @@ func TestPackTier(t *testing.T) { } } +/* func TestReadSpliceInfo(t *testing.T) { var tsig uint64 = 0x072bd0050 var segdur uint64 = 0x0001a599b0 @@ -57,44 +57,40 @@ func TestReadSpliceInfo(t *testing.T) { t.Fatalf("want %s, got %s", want, got) } } +*/ func TestDecodeSpliceInfo(t *testing.T) { - var tsig uint64 = 0x072bd0050 - want := &SpliceInfo{ - SAPType: SAPNone, - Tier: 0x0fff, - Command: &Command{ - Type: TimeSignal, - TimeSignal: &tsig, - }, - Descriptors: []SpliceDescriptor{ - { - Tag: TagSegmentation, - ID: binary.BigEndian.Uint32([]byte(DescriptorIDCUEI)), - Data: []byte("TODO"), - }, - }, - CRC32: 0x9ac9d17e, - } - b, err := base64.StdEncoding.DecodeString("/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg==") // sample 14.1 - if err != nil { - t.Fatal("decode example splice info:", err) - } - - info, err := decodeSpliceInfo(b) - if err != nil { - t.Fatalf("decode splice info: %v", err) - } - if want.SAPType != info.SAPType { - t.Errorf("want SAPType %s, got %s", want.SAPType, info.SAPType) - } - if want.Tier != info.Tier { - t.Errorf("want tier %#x, got %#x", want.Tier, info.Tier) - } - if *want.Command.TimeSignal != *info.Command.TimeSignal { - t.Errorf("want timesig %x, got %x", *want.Command.TimeSignal, *info.Command.TimeSignal) - } - if !reflect.DeepEqual(want, info) { - t.Errorf("decode splice info: want %+v, got %+v", want, info) + for _, tt := range samples { + t.Run(tt.name, func(t *testing.T) { + b, err := base64.StdEncoding.DecodeString(tt.encoded) + if err != nil { + t.Fatal("decode example splice info:", err) + } + info, err := decodeSpliceInfo(b) + if err != nil { + t.Fatalf("decode splice info: %v", err) + } + if tt.want.SAPType != info.SAPType { + t.Errorf("want SAPType %s, got %s", tt.want.SAPType, info.SAPType) + } + if tt.want.Tier != info.Tier { + t.Errorf("want tier %#x, got %#x", tt.want.Tier, info.Tier) + } + if *tt.want.Command.TimeSignal != *info.Command.TimeSignal { + t.Errorf("want timesig %x, got %x", *tt.want.Command.TimeSignal, *info.Command.TimeSignal) + } + wd := info.Descriptors[0].(SegmentationDescriptor) + d, ok := info.Descriptors[0].(SegmentationDescriptor) + if !ok { + t.Errorf("want %T, got %T", wd, info.Descriptors[0]) + } else { + if wd.UPID.Type != d.UPID.Type { + t.Errorf("want upid type %d, got %d", wd.UPID.Type, d.UPID.Type) + } + } + if !reflect.DeepEqual(tt.want, info) { + t.Errorf("decode splice info: want %+v, got %+v", tt.want, info) + } + }) } }