@@ -38,28 +38,34 @@ func TestParseProtocolInfo(t *testing.T) {
3838 }
3939}
4040
41- func TestParseProtocolInfoMatchesContentFormat (t * testing.T ) {
41+ func TestParseProtocolInfoMatchesMediaCategory (t * testing.T ) {
4242 response := func (sink string ) []byte {
4343 return []byte (`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:GetProtocolInfoResponse xmlns:u="urn:schemas-upnp-org:service:ConnectionManager:1"><Sink>` + sink + `</Sink></u:GetProtocolInfoResponse></s:Body></s:Envelope>` )
4444 }
4545
46- tests := []struct {
46+ tt := []struct {
4747 name string
4848 sink string
4949 mt string
5050 want bool
5151 }{
5252 {name : "exact MIME with different additional info" , sink : `http-get:*:video/mp4:DLNA.ORG_CI=0` , mt : "video/mp4" , want : true },
53- {name : "matching MIME parameters" , sink : `http-get:*:video/mp4;profile=main:*` , mt : "video/mp4;profile=main" , want : true },
54- {name : "different MIME parameters" , sink : `http-get:*:video/mp4;profile=main:*` , mt : "video/mp4;profile=high" , want : false },
55- {name : "case-sensitive MIME parameter" , sink : `http-get:*:multipart/mixed;boundary=CaseSensitive:*` , mt : "multipart/mixed;boundary=casesensitive" , want : false },
56- {name : "MIME subtype wildcard is not a wildcard" , sink : `http-get:*:video/*:*` , mt : "video/x-matroska" , want : false },
53+ {name : "Samsung Matroska alias" , sink : `http-get:*:video/x-mkv:*` , mt : "video/x-matroska" , want : true },
54+ {name : "unlisted video format" , sink : `http-get:*:video/mpeg:*` , mt : "video/mp4" , want : true },
55+ {name : "unlisted audio format" , sink : `http-get:*:audio/mpeg:*` , mt : "audio/flac" , want : true },
56+ {name : "unlisted image format" , sink : `http-get:*:image/jpeg:*` , mt : "image/png" , want : true },
57+ {name : "category case and whitespace" , sink : `http-get:*: VIDEO/MPEG :*` , mt : " Video/MP4 " , want : true },
58+ {name : "MIME parameters do not restrict category" , sink : `http-get:*:video/mp4;profile=main:*` , mt : "video/mp4;profile=high" , want : true },
59+ {name : "video category wildcard" , sink : `http-get:*:video/*:*` , mt : "video/x-matroska" , want : true },
5760 {name : "whole MIME wildcard" , sink : `http-get:*:*:*` , mt : "video/x-matroska" , want : true },
5861 {name : "escaped feature comma" , sink : `http-get:*:video/mp4:vendor=one\,two` , mt : "video/mp4" , want : true },
59- {name : "wrong MIME" , sink : `http-get:*:audio/mpeg:*` , mt : "video/mp4" , want : false },
62+ {name : "audio renderer rejects video" , sink : `http-get:*:audio/mpeg:*` , mt : "video/mp4" , want : false },
63+ {name : "audio wildcard rejects video" , sink : `http-get:*:audio/*:*` , mt : "video/mp4" , want : false },
64+ {name : "video renderer rejects images" , sink : `http-get:*:video/mp4:*` , mt : "image/jpeg" , want : false },
65+ {name : "wrong transport rejects same category" , sink : `rtsp-rtp-udp:*:video/mpeg:*` , mt : "video/mp4" , want : false },
6066 {name : "empty Sink is permissive" , sink : `` , mt : "video/mp4" , want : true },
6167 }
62- for _ , test := range tests {
68+ for _ , test := range tt {
6369 t .Run (test .name , func (t * testing.T ) {
6470 err := parseProtocolInfo (response (test .sink ), test .mt )
6571 if (err == nil ) != test .want {
@@ -340,15 +346,18 @@ func TestGetProtocolInfoSkipsWhenConnectionManagerMissing(t *testing.T) {
340346 }
341347}
342348
343- func TestGetProtocolInfoUsesTranscodedWireMIME (t * testing.T ) {
349+ func TestGetProtocolInfoAllowsUnlistedVideoFormat (t * testing.T ) {
344350 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
345351 _ , _ = w .Write ([]byte (`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:GetProtocolInfoResponse xmlns:u="urn:schemas-upnp-org:service:ConnectionManager:1"><Sink>http-get:*:video/mpeg:*</Sink></u:GetProtocolInfoResponse></s:Body></s:Envelope>` ))
346352 }))
347353 defer srv .Close ()
348354
349- p := & TVPayload {ConnectionManagerURL : srv .URL , MediaType : "video/x-matroska" , Transcode : true }
355+ p := & TVPayload {ConnectionManagerURL : srv .URL , MediaType : "video/x-matroska" }
350356 if err := p .GetProtocolInfo (); err != nil {
351- t .Fatalf ("GetProtocolInfo() err = %v, want wire MIME match" , err )
357+ t .Fatalf ("GetProtocolInfo() err = %v, want video category match" , err )
358+ }
359+ if p .MediaType != "video/x-matroska" {
360+ t .Fatalf ("GetProtocolInfo() changed resource MIME to %q" , p .MediaType )
352361 }
353362}
354363
0 commit comments