From 0a79ac34744c0842fd543c3769c740b4dc447924 Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 9 Jan 2020 16:03:52 +1030 Subject: [PATCH 1/3] Fixed mjpeg extract.go returning errors when it should not. --- codec/mjpeg/extract.go | 1 + 1 file changed, 1 insertion(+) diff --git a/codec/mjpeg/extract.go b/codec/mjpeg/extract.go index d0e515f2..d8baa7a1 100644 --- a/codec/mjpeg/extract.go +++ b/codec/mjpeg/extract.go @@ -74,6 +74,7 @@ func (e *Extractor) Extract(dst io.Writer, src io.Reader, delay time.Duration) e err = ctx.ParsePayload(p, m) switch err { + case nil: // Do nothing. case ErrNoFrameStart: // If no frame start then we continue until we get one. default: return fmt.Errorf("could not parse JPEG scan: %w", err) From 35a413c80ae0dbe196796d2366d9b961706372fa Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 14 Jan 2020 16:14:42 +1030 Subject: [PATCH 2/3] Added test file for extract.go --- codec/mjpeg/extract_test.go | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 codec/mjpeg/extract_test.go diff --git a/codec/mjpeg/extract_test.go b/codec/mjpeg/extract_test.go new file mode 100644 index 00000000..5d910841 --- /dev/null +++ b/codec/mjpeg/extract_test.go @@ -0,0 +1,71 @@ +/* +DESCRIPTION + extract_test.go provides testing for extract.go. + +AUTHOR + Scott Barnard + +LICENSE + Copyright (C) 2020 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 mjpeg + +import ( + "bytes" + "io" + "io/ioutil" + "testing" +) + +type testReader struct { + i int +} + +func (r *testReader) Read(b []byte) (int, error) { + if r.i >= len(testPackets) { + return 0, io.EOF + } + copy(b, testPackets[r.i]) + r.i++ + return len(testPackets[r.i-1]), nil +} + +func TestExtract(t *testing.T) { + const wantPath = "testdata/expect.mjpeg" + + got := &bytes.Buffer{} + + e := NewExtractor() + + r := &testReader{} + err := e.Extract(got, r, 0) + if err != nil { + t.Fatalf("could not extract: %v", err) + } + + want, err := ioutil.ReadFile(wantPath) + if err != nil { + t.Fatalf("could not read file for wanted MJPEG data: %v", err) + } + + t.Logf("len(got): %d\n", len(got.Bytes())) + t.Logf("len(want): %d\n", len(want)) + + if !bytes.Equal(got.Bytes(), want) { + t.Error("did not get expected result") + } +} From 8dbcf1c1482ee980b7d92c2e8f2a825b93be05a9 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 15 Jan 2020 13:22:41 +1030 Subject: [PATCH 3/3] extract_test.go: Simplified test code --- codec/mjpeg/extract_test.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/codec/mjpeg/extract_test.go b/codec/mjpeg/extract_test.go index 5d910841..a9f0bd98 100644 --- a/codec/mjpeg/extract_test.go +++ b/codec/mjpeg/extract_test.go @@ -45,26 +45,17 @@ func (r *testReader) Read(b []byte) (int, error) { } func TestExtract(t *testing.T) { - const wantPath = "testdata/expect.mjpeg" - got := &bytes.Buffer{} - - e := NewExtractor() - - r := &testReader{} - err := e.Extract(got, r, 0) + err := NewExtractor().Extract(got, &testReader{}, 0) if err != nil { t.Fatalf("could not extract: %v", err) } - want, err := ioutil.ReadFile(wantPath) + want, err := ioutil.ReadFile("testdata/expect.mjpeg") if err != nil { t.Fatalf("could not read file for wanted MJPEG data: %v", err) } - t.Logf("len(got): %d\n", len(got.Bytes())) - t.Logf("len(want): %d\n", len(want)) - if !bytes.Equal(got.Bytes(), want) { t.Error("did not get expected result") }