mirror of https://bitbucket.org/ausocean/av.git
Merge branch 'master' into m3u-files
This commit is contained in:
commit
e58e95f3ed
|
@ -74,6 +74,7 @@ func (e *Extractor) Extract(dst io.Writer, src io.Reader, delay time.Duration) e
|
||||||
|
|
||||||
err = ctx.ParsePayload(p, m)
|
err = ctx.ParsePayload(p, m)
|
||||||
switch err {
|
switch err {
|
||||||
|
case nil: // Do nothing.
|
||||||
case ErrNoFrameStart: // If no frame start then we continue until we get one.
|
case ErrNoFrameStart: // If no frame start then we continue until we get one.
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("could not parse JPEG scan: %w", err)
|
return fmt.Errorf("could not parse JPEG scan: %w", err)
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
DESCRIPTION
|
||||||
|
extract_test.go provides testing for extract.go.
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
Scott Barnard <scott@ausocean.org>
|
||||||
|
|
||||||
|
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) {
|
||||||
|
got := &bytes.Buffer{}
|
||||||
|
err := NewExtractor().Extract(got, &testReader{}, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not extract: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want, err := ioutil.ReadFile("testdata/expect.mjpeg")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not read file for wanted MJPEG data: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(got.Bytes(), want) {
|
||||||
|
t.Error("did not get expected result")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue