commit 0282f4221f089db5a75bf993a81f7e444253a418
parent 2611483e348541c03d648c6455415a50298bda3e
Author: Oliver Lowe <o@olowe.co>
Date: Sun, 30 Jun 2024 13:41:08 +1000
sdp: add test cases for different, bad, session descriptions
This exposes a bug when we read testdata/out_of_order.sdp. That fix
will come soon!
Diffstat:
5 files changed, 89 insertions(+), 38 deletions(-)
diff --git a/sdp/sdp_test.go b/sdp/sdp_test.go
@@ -3,51 +3,70 @@ package sdp
import (
"net/mail"
"net/url"
+ "os"
"reflect"
- "strings"
"testing"
)
func TestReadSession(t *testing.T) {
- s := `
-v=0
-o=jdoe 3724394400 3724394405 IN IP4 198.51.100.1
-s=Call to John Smith
-i=SDP Offer #1
-u=http://www.jdoe.example.com/home.html
-e=Jane Doe <jane@jdoe.example.com>
-p=+1 617 555-6011
-c=IN IP4 198.51.100.1
-t=0 0
-m=audio 49170 RTP/AVP 0
-m=audio 49180 RTP/AVP 0
-m=video 51372 RTP/AVP 99
-c=IN IP6 2001:db8::2
-a=rtpmap:99 h263-1998/90000`
- want := Session{
- Name: "Call to John Smith",
- Origin: Origin{
- Username: "jdoe",
- ID: 3724394400,
- Version: 3724394405,
- Network: "IN",
- AddressType: "IP4",
- Address: "198.51.100.1",
+ var cases = []struct {
+ name string
+ want Session
+ err bool
+ }{
+ {
+ name: "good.sdp",
+ want: Session{
+ Name: "Call to John Smith",
+ Origin: Origin{"jdoe", 3724394400, 3724394405, "IN", "IP4", "198.51.100.1"},
+ Info: "SDP Offer #1",
+ URI: &url.URL{
+ Scheme: "http",
+ Host: "www.jdoe.example.com",
+ Path: "/home.html",
+ },
+ Email: &mail.Address{"Jane Doe", "jane@jdoe.example.com"},
+ Phone: "+1 617 555-6011",
+ },
},
- Info: "SDP Offer #1",
- URI: &url.URL{Scheme: "http",
- Host: "www.jdoe.example.com",
- Path: "/home.html",
+ {
+ name: "some_optional.sdp",
+ want: Session{
+ Origin: Origin{"jdoe", 3724394400, 3724394405, "IN", "IP4", "198.51.100.1"},
+ Name: "Call to John Smith",
+ Email: &mail.Address{"Jane Doe", "jane@jdoe.example.com"},
+ },
+ },
+ {
+ name: "missing_origin.sdp",
+ want: Session{},
+ err: true,
+ },
+ {
+ name: "out_of_order.sdp",
+ want: Session{},
+ err: true,
},
- Email: &mail.Address{"Jane Doe", "jane@jdoe.example.com"},
- Phone: "+1 617 555-6011",
- }
- session, err := ReadSession(strings.NewReader(s))
- if err != nil {
- t.Fatalf("read session: %v", err)
}
- if !reflect.DeepEqual(*session, want) {
- t.Errorf("got %+v\nwant %+v\n", *session, want)
+ for _, tt := range cases {
+ t.Run(tt.name, func(t *testing.T) {
+ f, err := os.Open("testdata/" + tt.name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ session, err := ReadSession(f)
+ if err == nil && tt.err {
+ t.Fatal("unexpected nil error")
+ } else if err != nil && tt.err {
+ return
+ } else if err != nil && !tt.err {
+ t.Fatalf("read session: %v", err)
+ }
+ if !reflect.DeepEqual(*session, tt.want) {
+ t.Errorf("got %+v\nwant %+v\n", *session, tt.want)
+ }
+ t.Errorf("TODO still not parsing all fields")
+ })
}
- t.Errorf("TODO still not parsing all fields")
}
diff --git a/sdp/testdata/good.sdp b/sdp/testdata/good.sdp
@@ -0,0 +1,14 @@
+v=0
+o=jdoe 3724394400 3724394405 IN IP4 198.51.100.1
+s=Call to John Smith
+i=SDP Offer #1
+u=http://www.jdoe.example.com/home.html
+e=Jane Doe <jane@jdoe.example.com>
+p=+1 617 555-6011
+c=IN IP4 198.51.100.1
+t=0 0
+m=audio 49170 RTP/AVP 0
+m=audio 49180 RTP/AVP 0
+m=video 51372 RTP/AVP 99
+c=IN IP6 2001:db8::2
+a=rtpmap:99 h263-1998/90000
diff --git a/sdp/testdata/missing_origin.sdp b/sdp/testdata/missing_origin.sdp
@@ -0,0 +1,6 @@
+v=0
+s=Call to John Smith
+i=SDP Offer #1
+u=http://www.jdoe.example.com/home.html
+e=Jane Doe <jane@jdoe.example.com>
+p=+1 617 555-6011
diff --git a/sdp/testdata/out_of_order.sdp b/sdp/testdata/out_of_order.sdp
@@ -0,0 +1,8 @@
+v=0
+o=jdoe 3724394400 3724394405 IN IP4 198.51.100.1
+s=Call to John Smith
+i=SDP Offer #1
+p=+1 617 555-6011
+u=http://www.jdoe.example.com/home.html
+e=Jane Doe <jane@jdoe.example.com>
+c=IN IP4 198.51.100.1
diff --git a/sdp/testdata/some_optional.sdp b/sdp/testdata/some_optional.sdp
@@ -0,0 +1,4 @@
+v=0
+o=jdoe 3724394400 3724394405 IN IP4 198.51.100.1
+s=Call to John Smith
+e=Jane Doe <jane@jdoe.example.com>