mirror of https://bitbucket.org/ausocean/av.git
protocol/rtsp: TestReadResponse now working
This commit is contained in:
parent
d2b76fab36
commit
86bf4cdb90
|
@ -148,19 +148,12 @@ func ReadResponse(r io.Reader) (*Response, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
text := scanner.Text()
|
||||
fmt.Printf("text: %v\n", text)
|
||||
parts := strings.SplitN(text, ":", 2)
|
||||
fmt.Printf("text: %v\n", parts)
|
||||
parts := strings.SplitN(scanner.Text(), ":", 2)
|
||||
if len(parts) < 2 {
|
||||
break
|
||||
}
|
||||
p1 := strings.TrimSpace(parts[0])
|
||||
p2 := strings.TrimSpace(parts[1])
|
||||
fmt.Printf("p1: %v\n,p2: %v\n", p1, p2)
|
||||
resp.Header.Add(p1, p2)
|
||||
resp.Header.Add(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))
|
||||
}
|
||||
fmt.Printf("header: %v", resp.Header)
|
||||
// Get the content length from the header.
|
||||
resp.ContentLength, _ = strconv.Atoi(resp.Header.Get("Content-Length"))
|
||||
|
||||
|
|
|
@ -284,7 +284,6 @@ func TestReadResponse(t *testing.T) {
|
|||
0x53, 0x45, 0x54, 0x5f, 0x50, 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x0d, 0x0a, 0x0d, // |SET_PARAMETER...|
|
||||
0x0a,
|
||||
}
|
||||
fmt.Printf("string: %v", string(input))
|
||||
expect := Response{
|
||||
Proto: "RTSP",
|
||||
ProtoMajor: 1,
|
||||
|
@ -298,7 +297,6 @@ func TestReadResponse(t *testing.T) {
|
|||
},
|
||||
}
|
||||
got, err := ReadResponse(bytes.NewReader(input))
|
||||
fmt.Printf("resp: %v", got.String())
|
||||
if err != nil {
|
||||
t.Fatalf("should not have got error: %v", err)
|
||||
}
|
||||
|
@ -309,7 +307,7 @@ func TestReadResponse(t *testing.T) {
|
|||
}
|
||||
|
||||
func respEqual(got, want Response) bool {
|
||||
for i, f := range [][2]interface{}{
|
||||
for _, f := range [][2]interface{}{
|
||||
{got.Proto, want.Proto},
|
||||
{got.ProtoMajor, want.ProtoMajor},
|
||||
{got.ProtoMinor, want.ProtoMinor},
|
||||
|
@ -317,25 +315,23 @@ func respEqual(got, want Response) bool {
|
|||
{got.ContentLength, want.ContentLength},
|
||||
} {
|
||||
if f[0] != f[1] {
|
||||
fmt.Printf("at i: %v", i)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if len(got.Header) != len(want.Header) {
|
||||
fmt.Println("here1")
|
||||
return false
|
||||
}
|
||||
|
||||
for k, v := range got.Header {
|
||||
if k == "Cseq" {
|
||||
continue
|
||||
}
|
||||
if len(v) != len(want.Header[k]) {
|
||||
fmt.Printf("len(v): %v, len(want.Header): %v", len(v), len(want.Header[k]))
|
||||
fmt.Printf("k: %v", k)
|
||||
return false
|
||||
}
|
||||
for i, _v := range v {
|
||||
if _v != want.Header[k][i] {
|
||||
fmt.Printf("k: %v, v: %v, _v: %v", k, v, _v)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue