/* NAME flv_test.go DESCRIPTION flv_test.go provides testing for functionality provided in flv.go. AUTHORS Saxon A. Nelson-Milton LICENSE Copyright (C) 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 flv import ( "bytes" "testing" ) // TestVideoTagBytes checks that we can correctly get a []byte representation // of a VideoTag using VideoTag.Bytes(). func TestVideoTagBytes(t *testing.T) { tests := []struct { tag VideoTag expected []byte }{ { tag: VideoTag{ TagType: VideoTagType, DataSize: 12, Timestamp: 1234, TimestampExtended: 56, FrameType: KeyFrameType, Codec: H264, PacketType: AVCNALU, CompositionTime: 0, Data: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, }, expected: []byte{ 0x09, // TagType. 0x00, 0x00, 0x0c, // DataSize. 0x00, 0x04, 0xd2, // Timestamp. 0x38, // TimestampExtended. 0x00, 0x00, 0x00, // StreamID. (always 0) 0x17, // FrameType=0001, Codec=0111 0x01, // PacketType. 0x00, 0x00, 0x00, // CompositionTime 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // VideoData. 0x00, 0x00, 0x00, 0x00, // previousTagSize. }, }, } for testNum, test := range tests { got := test.tag.Bytes() if !bytes.Equal(got, test.expected) { t.Errorf("did not get expected result for test: %v.\n Got: %v\n Want: %v\n", testNum, got, test.expected) } } } // TestAudioTagBytes checks that we can correctly get a []byte representation of // an AudioTag using AudioTag.Bytes(). func TestAudioTagBytes(t *testing.T) { tests := []struct { tag AudioTag expected []byte }{ { tag: AudioTag{ TagType: AudioTagType, DataSize: 8, Timestamp: 1234, TimestampExtended: 56, SoundFormat: AACAudioFormat, SoundRate: 3, SoundSize: true, SoundType: true, Data: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, }, expected: []byte{ 0x08, // TagType. 0x00, 0x00, 0x08, // DataSize. 0x00, 0x04, 0xd2, // Timestamp. 0x38, // TimestampExtended. 0x00, 0x00, 0x00, // StreamID. (always 0) 0xaf, // SoundFormat=1010,SoundRate=11,SoundSize=1,SoundType=1 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // AudioData. 0x00, 0x00, 0x00, 0x00, // previousTagSize. }, }, } for testNum, test := range tests { got := test.tag.Bytes() if !bytes.Equal(got, test.expected) { t.Errorf("did not get expected result for test: %v.\n Got: %v\n Want: %v\n", testNum, got, test.expected) } } }