/* DESCRIPTION jpeg_test.go provides testing for utilities found in jpeg.go. AUTHOR Saxon Nelson-Milton 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/ioutil" "testing" "bitbucket.org/ausocean/av/protocol/rtp" ) func TestParsePayload(t *testing.T) { const ( wantPath = "testdata/expect.mjpeg" noOfPkts = 5629 ) got := &bytes.Buffer{} c := NewContext(got) for i, pkt := range testPackets { p, err := rtp.Payload(pkt) if err != nil { t.Fatalf("could not get payload for packet %d: %v", i, err) } m, err := rtp.Marker(pkt) if err != nil { t.Fatalf("could not get marker for packet %d: %v", i, err) } err = c.ParsePayload(p, m) if err != nil { t.Fatalf("could not parse pyload for packet %d: %v", i, err) } } want, err := ioutil.ReadFile(wantPath) 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") } }