2019-01-30 04:56:51 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
metaEncode_test.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
metaEncode_test.go is Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package mts
|
|
|
|
|
2019-01-30 05:53:07 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2019-01-30 04:56:51 +03:00
|
|
|
|
2019-03-25 04:21:03 +03:00
|
|
|
"bitbucket.org/ausocean/av/container/mts/meta"
|
|
|
|
"bitbucket.org/ausocean/av/container/mts/psi"
|
2019-01-30 05:53:07 +03:00
|
|
|
)
|
|
|
|
|
2019-01-30 08:07:15 +03:00
|
|
|
const (
|
|
|
|
errNotExpectedOut = "Unexpected output. \n Got : %v\n, Want: %v\n"
|
|
|
|
errUnexpectedErr = "Unexpected error: %v\n"
|
|
|
|
)
|
|
|
|
|
2019-01-30 05:53:07 +03:00
|
|
|
const fps = 25
|
2019-01-30 04:56:51 +03:00
|
|
|
|
2019-02-07 03:25:58 +03:00
|
|
|
// TestMetaEncode1 checks that we can externally add a single metadata entry to
|
|
|
|
// the mts global Meta meta.Data struct and then successfully have the mts encoder
|
|
|
|
// write this to psi.
|
2019-01-30 08:52:57 +03:00
|
|
|
func TestMetaEncode1(t *testing.T) {
|
2019-02-07 03:18:25 +03:00
|
|
|
Meta = meta.New()
|
2019-04-15 02:12:56 +03:00
|
|
|
var buf buffer
|
|
|
|
e := NewEncoder(&buf, fps, Video)
|
2019-01-30 05:53:07 +03:00
|
|
|
Meta.Add("ts", "12345678")
|
2019-01-30 08:07:15 +03:00
|
|
|
if err := e.writePSI(); err != nil {
|
|
|
|
t.Errorf(errUnexpectedErr, err.Error())
|
|
|
|
}
|
2019-04-15 02:12:56 +03:00
|
|
|
out := (*bytes.Buffer)(&buf).Bytes()
|
2019-01-30 08:07:15 +03:00
|
|
|
got := out[PacketSize+4:]
|
|
|
|
|
2019-01-30 05:53:07 +03:00
|
|
|
want := []byte{
|
2019-01-30 08:07:15 +03:00
|
|
|
0x00, 0x02, 0xb0, 0x23, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x11,
|
|
|
|
psi.MetadataTag, // Descriptor tag
|
|
|
|
0x0f, // Length of bytes to follow
|
|
|
|
0x00, 0x10, 0x00, 0x0b, 't', 's', '=', '1', '2', '3', '4', '5', '6', '7', '8', // timestamp
|
2019-01-30 05:53:07 +03:00
|
|
|
0x1b, 0xe1, 0x00, 0xf0, 0x00,
|
|
|
|
}
|
2019-01-30 08:07:15 +03:00
|
|
|
want = psi.AddCrc(want)
|
|
|
|
want = psi.AddPadding(want)
|
|
|
|
if !bytes.Equal(got, want) {
|
|
|
|
t.Errorf(errNotExpectedOut, got, want)
|
|
|
|
}
|
2019-01-30 04:56:51 +03:00
|
|
|
}
|
2019-01-30 08:52:57 +03:00
|
|
|
|
2019-02-07 03:25:58 +03:00
|
|
|
// TestMetaEncode2 checks that we can externally add two metadata entries to the
|
|
|
|
// Meta meta.Data global and then have the mts encoder successfully encode this
|
|
|
|
// into psi.
|
2019-01-30 08:52:57 +03:00
|
|
|
func TestMetaEncode2(t *testing.T) {
|
2019-02-07 03:18:25 +03:00
|
|
|
Meta = meta.New()
|
2019-04-15 02:12:56 +03:00
|
|
|
var buf buffer
|
|
|
|
e := NewEncoder(&buf, fps, Video)
|
2019-01-30 08:52:57 +03:00
|
|
|
Meta.Add("ts", "12345678")
|
|
|
|
Meta.Add("loc", "1234,4321,1234")
|
|
|
|
if err := e.writePSI(); err != nil {
|
|
|
|
t.Errorf(errUnexpectedErr, err.Error())
|
|
|
|
}
|
2019-04-15 02:12:56 +03:00
|
|
|
out := (*bytes.Buffer)(&buf).Bytes()
|
2019-01-30 08:52:57 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|