From b3a57557e2d6193e2b8023407c8b2c229a3ee474 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 4 Jul 2018 22:05:38 +0930 Subject: [PATCH] Using ReadAll for reding instead of just read --- parser/parser_test.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index cb95ad39..2a2ddc7b 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -28,6 +28,7 @@ LICENSE package parser import ( + "io/ioutil" "log" "os" "strconv" @@ -36,7 +37,9 @@ import ( const ( mjpegInputFileName = "testInput/testInput.avi" - h264fName = "../../test/test-data/av/input/betterInput.h264" + h264fName = "../../test/test-data/av/input/betterInput.h264" + nOfFrames = 4 + outChanSize = 100 ) func TestH264Parser(t *testing.T) { @@ -48,16 +51,8 @@ func TestH264Parser(t *testing.T) { return } - log.Println("Getting file stats!") - stats, err := inputFile.Stat() - if err != nil { - t.Errorf("Could not get input file stats!") - return - } - - log.Println("Creating space for file data and reading!") - data := make([]byte, stats.Size()) - _, err = inputFile.Read(data) + log.Println("Reading data from file!") + data, err := ioutil.ReadAll(inputFile) if err != nil { t.Errorf("Should not have got read error!") return @@ -66,7 +61,7 @@ func TestH264Parser(t *testing.T) { // Create 'parser' and start it up log.Println("Creating parser!") parser := NewH264Parser() - parser.SetOutputChan(make(chan []byte, 10000)) + parser.SetOutputChan(make(chan []byte, outChanSize)) parser.Start() count := 0 @@ -75,7 +70,7 @@ func TestH264Parser(t *testing.T) { // nothing select { case parser.InputChan() <- data[i]: - case frame:=<-parser.OutputChan(): + case frame := <-parser.OutputChan(): outputFile, err := os.Create("testOutput/" + strconv.Itoa(count) + ".h264_frame") if err != nil { t.Errorf("Should not have got error creating output file!") @@ -84,7 +79,7 @@ func TestH264Parser(t *testing.T) { outputFile.Write(frame) outputFile.Close() count++ - if count > 4 { + if count > nOfFrames { return } default: @@ -92,7 +87,6 @@ func TestH264Parser(t *testing.T) { } } - /* func TestMJPEGParser(t *testing.T) { log.Println("Opening input file!")