From 48645d1cf3a160ab271cc19b6d1a35dfa67712bd Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 8 May 2019 15:14:35 +0930 Subject: [PATCH 1/4] container/flv/flv_test.go: wrote test TestVideoTagBytes Wrote test TestVideoTagBytes which checks that we can get a valid []byte representation of a VideoTag. The test is passing. --- container/flv/flv_test.go | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 container/flv/flv_test.go diff --git a/container/flv/flv_test.go b/container/flv/flv_test.go new file mode 100644 index 00000000..42aa499c --- /dev/null +++ b/container/flv/flv_test.go @@ -0,0 +1,77 @@ +/* +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" +) + +func TestVideoTagBytes(t *testing.T) { + tests := []struct { + tag VideoTag + expected []byte + }{ + { + tag: VideoTag{ + TagType: VideoTagType, + DataSize: 12, + Timestamp: 1234, + TimestampExtended: 56, + FrameType: KeyFrameType, // 1 + Codec: H264, // 7 + PacketType: AVCNALU, // 1 + 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) + } + } +} + +func TestAudioTagBytes(t *testing.T) { + +} From 553ba8dc54592d99bc975519d786de80399912b0 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 8 May 2019 15:39:12 +0930 Subject: [PATCH 2/4] container/flv/audio_test.go: added test TestAudioTagBytes Wrote test TestAudioTagBytes to check that we can correctly get a []byte representation of an AudioTag. --- container/flv/flv_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/container/flv/flv_test.go b/container/flv/flv_test.go index 42aa499c..847138cb 100644 --- a/container/flv/flv_test.go +++ b/container/flv/flv_test.go @@ -73,5 +73,39 @@ func TestVideoTagBytes(t *testing.T) { } 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) + } + } } From 4f2d2f7c26327867187f41e8fbb08d960bebd5e7 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 8 May 2019 15:41:19 +0930 Subject: [PATCH 3/4] container/flv/flv_test.go: commented test functions --- container/flv/flv_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/container/flv/flv_test.go b/container/flv/flv_test.go index 847138cb..f25ef26e 100644 --- a/container/flv/flv_test.go +++ b/container/flv/flv_test.go @@ -32,6 +32,8 @@ import ( "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 @@ -72,6 +74,8 @@ func TestVideoTagBytes(t *testing.T) { } } +// 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 From 7955018ab0cd9d2a0729fe6f1b0ba00b2e64b9cb Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 8 May 2019 17:06:23 +0930 Subject: [PATCH 4/4] container/flv: removed some unecessary comments --- container/flv/flv_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/container/flv/flv_test.go b/container/flv/flv_test.go index f25ef26e..66f51f4c 100644 --- a/container/flv/flv_test.go +++ b/container/flv/flv_test.go @@ -45,9 +45,9 @@ func TestVideoTagBytes(t *testing.T) { DataSize: 12, Timestamp: 1234, TimestampExtended: 56, - FrameType: KeyFrameType, // 1 - Codec: H264, // 7 - PacketType: AVCNALU, // 1 + FrameType: KeyFrameType, + Codec: H264, + PacketType: AVCNALU, CompositionTime: 0, Data: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, },