mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
base: add tests
This commit is contained in:
@@ -177,9 +177,17 @@ func TestRequestReadErrors(t *testing.T) {
|
|||||||
"missing eol",
|
"missing eol",
|
||||||
[]byte("GET rtsp://testing123/test RTSP/1.0"),
|
[]byte("GET rtsp://testing123/test RTSP/1.0"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"empty method",
|
||||||
|
[]byte(" rtsp://testing123 RTSP/1.0\r\n"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"empty URL",
|
"empty URL",
|
||||||
[]byte("GET http://testing123 RTSP/1.0\r\n"),
|
[]byte("GET RTSP/1.0\r\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"empty protocol",
|
||||||
|
[]byte("GET http://testing123 \r\n"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid URL",
|
"invalid URL",
|
||||||
|
@@ -14,23 +14,7 @@ var casesResponse = []struct {
|
|||||||
res Response
|
res Response
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"ok with single header",
|
"ok",
|
||||||
[]byte("RTSP/1.0 200 OK\r\n" +
|
|
||||||
"CSeq: 1\r\n" +
|
|
||||||
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n" +
|
|
||||||
"\r\n",
|
|
||||||
),
|
|
||||||
Response{
|
|
||||||
StatusCode: StatusOK,
|
|
||||||
StatusMessage: "OK",
|
|
||||||
Header: Header{
|
|
||||||
"CSeq": HeaderValue{"1"},
|
|
||||||
"Public": HeaderValue{"DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ok with multiple headers",
|
|
||||||
[]byte("RTSP/1.0 200 OK\r\n" +
|
[]byte("RTSP/1.0 200 OK\r\n" +
|
||||||
"CSeq: 2\r\n" +
|
"CSeq: 2\r\n" +
|
||||||
"Date: Sat, Aug 16 2014 02:22:28 GMT\r\n" +
|
"Date: Sat, Aug 16 2014 02:22:28 GMT\r\n" +
|
||||||
@@ -155,6 +139,10 @@ func TestResponseReadErrors(t *testing.T) {
|
|||||||
"missing eol",
|
"missing eol",
|
||||||
[]byte("RTSP/1.0 200 OK"),
|
[]byte("RTSP/1.0 200 OK"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"missing eol 2",
|
||||||
|
[]byte("RTSP/1.0 200 OK\r"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"invalid protocol",
|
"invalid protocol",
|
||||||
[]byte("RTSP/2.0 200 OK\r\n"),
|
[]byte("RTSP/2.0 200 OK\r\n"),
|
||||||
@@ -163,6 +151,10 @@ func TestResponseReadErrors(t *testing.T) {
|
|||||||
"invalid code",
|
"invalid code",
|
||||||
[]byte("RTSP/2.0 string OK\r\n"),
|
[]byte("RTSP/2.0 string OK\r\n"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"empty message",
|
||||||
|
[]byte("RTSP/2.0 string \r\n"),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
var res Response
|
var res Response
|
||||||
@@ -200,3 +192,17 @@ func TestResponseWriteAutoFillStatus(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, byts, buf.Bytes())
|
require.Equal(t, byts, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadIgnoreFrames(t *testing.T) {
|
||||||
|
byts := []byte{0x24, 0x6, 0x0, 0x4, 0x1, 0x2, 0x3, 0x4}
|
||||||
|
byts = append(byts, []byte("RTSP/1.0 200 OK\r\n"+
|
||||||
|
"CSeq: 1\r\n"+
|
||||||
|
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n"+
|
||||||
|
"\r\n")...)
|
||||||
|
|
||||||
|
rb := bufio.NewReader(bytes.NewBuffer(byts))
|
||||||
|
buf := make([]byte, 10)
|
||||||
|
var res Response
|
||||||
|
err := res.ReadIgnoreFrames(rb, buf)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user