2018-08-28 13:58:57 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
lex_test.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
2019-05-03 13:22:23 +03:00
|
|
|
lex_test.go provides tests for the lexer in lex.go.
|
2018-08-28 13:58:57 +03:00
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Dan Kortschak <dan@ausocean.org>
|
2019-05-24 04:08:54 +03:00
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
2018-08-28 13:58:57 +03:00
|
|
|
|
|
|
|
LICENSE
|
|
|
|
lex_test.go is Copyright (C) 2017 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.
|
|
|
|
*/
|
|
|
|
|
2019-04-26 14:01:12 +03:00
|
|
|
package h264
|
2018-08-28 13:58:57 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var h264Tests = []struct {
|
|
|
|
name string
|
|
|
|
input []byte
|
|
|
|
delay time.Duration
|
|
|
|
want [][]byte
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "null short",
|
|
|
|
input: []byte{0x00, 0x00, 0x01, 0x0},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x0}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "null short delayed",
|
|
|
|
input: []byte{0x00, 0x00, 0x01, 0x0},
|
|
|
|
delay: time.Millisecond,
|
|
|
|
want: [][]byte{{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x0}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full short type 1",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full short type 5",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x45, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x45, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full short type 8",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x48, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x48, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full short delayed",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: time.Millisecond,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full long type 1",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full long type 5",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x45, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x45, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full long type 8",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x48, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: 0,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x48, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "full long delayed",
|
|
|
|
input: []byte{
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd',
|
|
|
|
},
|
|
|
|
delay: time.Millisecond,
|
|
|
|
want: [][]byte{
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'u', 'l', 'l',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 'f', 'r', 'a', 'm', 'e',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x41, 'w', 'i', 't', 'h'},
|
|
|
|
{0x0, 0x0, 0x1, 0x9, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 'l', 'e', 'n', 'g', 't', 'h',
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 's', 'p', 'r', 'e', 'a', 'd'},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-03-09 07:58:07 +03:00
|
|
|
// FIXME: this needs to be adapted
|
|
|
|
/*
|
2018-08-28 13:58:57 +03:00
|
|
|
func TestH264(t *testing.T) {
|
|
|
|
for _, test := range h264Tests {
|
|
|
|
var buf chunkEncoder
|
2019-04-26 14:16:43 +03:00
|
|
|
err := Lex(&buf, bytes.NewReader(test.input), test.delay)
|
2018-08-28 13:58:57 +03:00
|
|
|
if fmt.Sprint(err) != fmt.Sprint(test.err) {
|
|
|
|
t.Errorf("unexpected error for %q: got:%v want:%v", test.name, err, test.err)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
got := [][]byte(buf)
|
|
|
|
if !reflect.DeepEqual(got, test.want) {
|
|
|
|
t.Errorf("unexpected result for %q:\ngot :%#v\nwant:%#v", test.name, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-09 07:58:07 +03:00
|
|
|
*/
|