From 1d9cb575053190a57fc65bfd9fc4fe228a0c6c78 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 30 Jan 2019 16:22:57 +1030 Subject: [PATCH] stream/mts/metaEncode_test.go: added another test to check behaviour when more meta data is added. --- stream/mts/metaEncode_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/stream/mts/metaEncode_test.go b/stream/mts/metaEncode_test.go index a914da2b..d372f20a 100644 --- a/stream/mts/metaEncode_test.go +++ b/stream/mts/metaEncode_test.go @@ -41,7 +41,7 @@ const ( const fps = 25 -func TestMetaEncode(t *testing.T) { +func TestMetaEncode1(t *testing.T) { var b []byte buf := bytes.NewBuffer(b) e := NewEncoder(buf, fps) @@ -65,3 +65,29 @@ func TestMetaEncode(t *testing.T) { t.Errorf(errNotExpectedOut, got, want) } } + +func TestMetaEncode2(t *testing.T) { + var b []byte + buf := bytes.NewBuffer(b) + e := NewEncoder(buf, fps) + Meta.Add("ts", "12345678") + Meta.Add("loc", "1234,4321,1234") + if err := e.writePSI(); err != nil { + t.Errorf(errUnexpectedErr, err.Error()) + } + out := buf.Bytes() + got := out[PacketSize+4:] + want := []byte{ + 0x00, 0x02, 0xb0, 0x36, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x24, + psi.MetadataTag, // Descriptor tag + 0x22, // Length of bytes to follow + 0x00, 0x10, 0x00, 0x1e, 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', '\t', // timestamp + 'l', 'o', 'c', '=', '1', '2', '3', '4', ',', '4', '3', '2', '1', ',', '1', '2', '3', '4', // location + 0x1b, 0xe1, 0x00, 0xf0, 0x00, + } + want = psi.AddCrc(want) + want = psi.AddPadding(want) + if !bytes.Equal(got, want) { + t.Errorf(errNotExpectedOut, got, want) + } +}