streaming

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

commit 2eb7f240b6667d726319ee16a9639cfb794db954
parent ccb2bb2323ba704025fe9ee71679e9a112be7c77
Author: Oliver Lowe <o@olowe.co>
Date:   Thu,  2 May 2024 16:43:18 +1000

internal/scte35: Only test binary encoding/decoding

Diffstat:
Minternal/scte35/scte35_test.go | 66+++---------------------------------------------------------------
Minternal/scte35/splice_info_section.go | 1-
Minternal/scte35/splice_info_section_test.go | 52----------------------------------------------------
Dinternal/scte35/testdata/saptype_missing.json | 35-----------------------------------
Dinternal/scte35/testdata/saptype_missing.xml | 11-----------
Dinternal/scte35/testdata/saptype_specified.json | 36------------------------------------
Dinternal/scte35/testdata/saptype_specified.xml | 11-----------
7 files changed, 3 insertions(+), 209 deletions(-)

diff --git a/internal/scte35/scte35_test.go b/internal/scte35/scte35_test.go @@ -18,8 +18,6 @@ package scte35 import ( "encoding/binary" - "encoding/json" - "encoding/xml" "errors" "testing" ) @@ -595,38 +593,10 @@ func TestDecodeBase64(t *testing.T) { if err != nil { t.Fatal(err) } - // test encode/decode XML - encodedXML := toXML(sis) - if toXML(&c.expected) != encodedXML { - t.Fatalf("encode xml: want %s, got %s", toXML(&c.expected), encodedXML) - } - var info SpliceInfoSection - if err := xml.Unmarshal([]byte(encodedXML), &info); err != nil { - t.Error(err) - } - // legacy 35's produce an "updated" binary so will not match if !c.legacy { - if c.binary != info.Base64() { - t.Errorf("re-encode to binary: want %s, got %s", c.binary, info.Base64()) - } - } - - // test encode/decode JSON - encodedJSON := toJSON(sis) - if toJSON(&c.expected) != encodedJSON { - t.Fatalf("encode to json: want %s, got %s", toJSON(&c.expected), encodedJSON) - } - info = SpliceInfoSection{} - - if err := json.Unmarshal([]byte(encodedJSON), &info); err != nil { - t.Fatal(err) - } - - // legacy 35's produce an "updated" binary so will not match - if !c.legacy { - if c.binary != info.Base64() { - t.Errorf("re-encode to binary: want %s, got %s", c.binary, info.Base64()) + if c.binary != sis.Base64() { + t.Errorf("re-encode to binary: want %s, got %s", c.binary, sis.Base64()) } } }) @@ -726,30 +696,10 @@ func TestDecodeHex(t *testing.T) { for k, c := range cases { t.Run(k, func(t *testing.T) { - sis, err := DecodeHex(c.hex) + _, err := DecodeHex(c.hex) if !errors.Is(c.err, err) { t.Fatalf("want error %v, got %v", c.err, err) } - - // test encode/decode XML - encodedXML := toXML(sis) - if toXML(&c.expected) != encodedXML { - t.Fatalf("encode xml: want %s, got %s", toXML(&c.expected), encodedXML) - } - var info SpliceInfoSection - if err := xml.Unmarshal([]byte(encodedXML), &info); err != nil { - t.Errorf("unmarshal back from xml: %v", err) - } - - // test encode/decode JSON - encodedJSON := toJSON(sis) - if toJSON(&c.expected) != encodedJSON { - t.Fatalf("encode json: want %s, got %s", toJSON(&c.expected), encodedJSON) - } - info = SpliceInfoSection{} - if err := json.Unmarshal([]byte(encodedJSON), &info); err != nil { - t.Errorf("unmarshal from json back into splice info: %v", err) - } }) } } @@ -801,16 +751,6 @@ func toBytes(i uint64) []byte { return b } -func toJSON(sis *SpliceInfoSection) string { - b, _ := json.MarshalIndent(sis, "", "\t") - return string(b) -} - -func toXML(sis *SpliceInfoSection) string { - b, _ := xml.MarshalIndent(sis, "", "\t") - return string(b) -} - func uint32ptr(i uint32) *uint32 { return &i } diff --git a/internal/scte35/splice_info_section.go b/internal/scte35/splice_info_section.go @@ -319,7 +319,6 @@ type iSIS struct { // SpliceCommand returns the polymorphic splice_command. func (i *iSIS) SpliceCommand() SpliceCommand { - // xml unmarshalls to the corresponding struct if i.SpliceNull != nil { return i.SpliceNull } diff --git a/internal/scte35/splice_info_section_test.go b/internal/scte35/splice_info_section_test.go @@ -1,14 +1,5 @@ package scte35 -import ( - "encoding/json" - "encoding/xml" - "os" - "path" - "strings" - "testing" -) - type sistest struct { name string sis SpliceInfoSection @@ -41,46 +32,3 @@ var tsis SpliceInfoSection = SpliceInfoSection{ }, }, } - -func TestSpliceInfoSection(t *testing.T) { - missingSAP := tsis - withSAP := tsis - withSAP.SAPType = SAPType1 - - var tests = []sistest{ - {"testdata/saptype_missing.xml", missingSAP}, - {"testdata/saptype_missing.json", missingSAP}, - {"testdata/saptype_specified.xml", withSAP}, - {"testdata/saptype_specified.json", withSAP}, - } - - for _, tt := range tests { - tname := path.Base(tt.name) - t.Run(tname, func(t *testing.T) { - b, err := os.ReadFile(tt.name) - if err != nil { - t.Fatal(err) - } - var got SpliceInfoSection - if strings.HasSuffix(tt.name, "json") { - if err := json.Unmarshal(b, &got); err != nil { - t.Fatal(err) - } - if toJSON(&tt.sis) != toJSON(&got) { - t.Error("remarshalled json different from source") - t.Logf("want: %s", toJSON(&tt.sis)) - t.Logf("got: %s", toJSON(&got)) - } - } else { - if err := xml.Unmarshal(b, &got); err != nil { - t.Fatal(err) - } - if toXML(&tt.sis) != toXML(&got) { - t.Error("remarshalled xml different from source") - t.Logf("want: %s", toXML(&tt.sis)) - t.Logf("got: %s", toXML(&got)) - } - } - }) - } -} diff --git a/internal/scte35/testdata/saptype_missing.json b/internal/scte35/testdata/saptype_missing.json @@ -1,34 +0,0 @@ -{ - "encryptedPacket": { - "cwIndex": 255 - }, - "spliceCommand": { - "type": 6, - "spliceTime": { - "ptsTime": 1924989008 - } - }, - "spliceDescriptors": [ - { - "type": 2, - "deliveryRestrictions": { - "archiveAllowedFlag": true, - "webDeliveryAllowedFlag": false, - "noRegionalBlackoutFlag": true, - "deviceRestrictions": 3 - }, - "segmentationUpids": [ - { - "segmentationUpidType": 8, - "format": "text", - "value": "748724618" - } - ], - "segmentationEventId": 1207959694, - "segmentationDuration": 27630000, - "segmentationTypeId": 52, - "segmentNum": 2 - } - ], - "tier": 4095 -} -\ No newline at end of file diff --git a/internal/scte35/testdata/saptype_missing.xml b/internal/scte35/testdata/saptype_missing.xml @@ -1,10 +0,0 @@ -<SpliceInfoSection xmlns="http://www.scte.org/schemas/35" tier="4095"> - <EncryptedPacket xmlns="http://www.scte.org/schemas/35" cwIndex="255"></EncryptedPacket> - <TimeSignal xmlns="http://www.scte.org/schemas/35"> - <SpliceTime xmlns="http://www.scte.org/schemas/35" ptsTime="1924989008"></SpliceTime> - </TimeSignal> - <SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="1207959694" segmentationDuration="27630000" segmentationTypeId="52" segmentNum="2"> - <DeliveryRestrictions xmlns="http://www.scte.org/schemas/35" archiveAllowedFlag="true" webDeliveryAllowedFlag="false" noRegionalBlackoutFlag="true" deviceRestrictions="3"></DeliveryRestrictions> - <SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="8">748724618</SegmentationUpid> - </SegmentationDescriptor> -</SpliceInfoSection> -\ No newline at end of file diff --git a/internal/scte35/testdata/saptype_specified.json b/internal/scte35/testdata/saptype_specified.json @@ -1,35 +0,0 @@ -{ - "encryptedPacket": { - "cwIndex": 255 - }, - "sapType": 0, - "spliceCommand": { - "type": 6, - "spliceTime": { - "ptsTime": 1924989008 - } - }, - "spliceDescriptors": [ - { - "type": 2, - "deliveryRestrictions": { - "archiveAllowedFlag": true, - "webDeliveryAllowedFlag": false, - "noRegionalBlackoutFlag": true, - "deviceRestrictions": 3 - }, - "segmentationUpids": [ - { - "segmentationUpidType": 8, - "format": "text", - "value": "748724618" - } - ], - "segmentationEventId": 1207959694, - "segmentationDuration": 27630000, - "segmentationTypeId": 52, - "segmentNum": 2 - } - ], - "tier": 4095 -} -\ No newline at end of file diff --git a/internal/scte35/testdata/saptype_specified.xml b/internal/scte35/testdata/saptype_specified.xml @@ -1,10 +0,0 @@ -<SpliceInfoSection xmlns="http://www.scte.org/schemas/35" tier="4095" sapType="0"> - <EncryptedPacket xmlns="http://www.scte.org/schemas/35" cwIndex="255"></EncryptedPacket> - <TimeSignal xmlns="http://www.scte.org/schemas/35"> - <SpliceTime xmlns="http://www.scte.org/schemas/35" ptsTime="1924989008"></SpliceTime> - </TimeSignal> - <SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="1207959694" segmentationDuration="27630000" segmentationTypeId="52" segmentNum="2"> - <DeliveryRestrictions xmlns="http://www.scte.org/schemas/35" archiveAllowedFlag="true" webDeliveryAllowedFlag="false" noRegionalBlackoutFlag="true" deviceRestrictions="3"></DeliveryRestrictions> - <SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="8">748724618</SegmentationUpid> - </SegmentationDescriptor> -</SpliceInfoSection> -\ No newline at end of file