package soapcalls import ( "testing" "github.com/alexballas/go2tv/soapcalls/utils" ) func TestSetAVTransportSoapBuild(t *testing.T) { tt := []struct { name string tv *TVPayload }{ { `setAVTransportSoapBuild Test #1`, &TVPayload{ MediaURL: `http://192.168.88.250:3500/video%20%26%20%27example%27.mp4`, MediaType: "video/mp4", SubtitlesURL: "http://192.168.88.250:3500/video_example.srt", Transcode: false, Seekable: true, }, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { seekflag := "00" if tc.tv.Seekable { seekflag = "01" } contentFeatures, err := utils.BuildContentFeatures(tc.tv.MediaType, seekflag, tc.tv.Transcode) if err != nil { t.Fatalf("%s: setAVTransportSoapBuild failed to build contentFeatures: %s", tc.name, err.Error()) } want := `0http://192.168.88.250:3500/video%20%26%20%27example%27.mp4<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sec="http://www.sec.co.kr/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="1" parentID="0" restricted="1"><sec:CaptionInfo sec:type="srt">http://192.168.88.250:3500/video_example.srt</sec:CaptionInfo><sec:CaptionInfoEx sec:type="srt">http://192.168.88.250:3500/video_example.srt</sec:CaptionInfoEx><dc:title>video 'example'.mp4</dc:title><upnp:class>object.item.videoItem.movie</upnp:class><res protocolInfo="http-get:*:video/mp4:` + contentFeatures + `">http://192.168.88.250:3500/video%20%26%20%27example%27.mp4</res><res protocolInfo="http-get:*:text/srt:*">http://192.168.88.250:3500/video_example.srt</res></item></DIDL-Lite>` out, err := setAVTransportSoapBuild(tc.tv) if err != nil { t.Fatalf("%s: Failed to call setAVTransportSoapBuild due to %s", tc.name, err.Error()) } if string(out) != want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, want) } }) } } func TestSetNextAVTransportSoapBuild(t *testing.T) { tt := []struct { name string tv *TVPayload }{ { `setNextAVTransportSoapBuild Test #1`, &TVPayload{ MediaURL: `http://192.168.88.250:3500/video%20%26%20%27example%27.mp4`, MediaType: "video/mp4", SubtitlesURL: "http://192.168.88.250:3500/video_example.srt", Transcode: false, Seekable: true, }, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { seekflag := "00" if tc.tv.Seekable { seekflag = "01" } contentFeatures, err := utils.BuildContentFeatures(tc.tv.MediaType, seekflag, tc.tv.Transcode) if err != nil { t.Fatalf("%s: setNextAVTransportSoapBuild failed to build contentFeatures: %s", tc.name, err.Error()) } want := `0http://192.168.88.250:3500/video%20%26%20%27example%27.mp4<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sec="http://www.sec.co.kr/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="1" parentID="0" restricted="1"><sec:CaptionInfo sec:type="srt">http://192.168.88.250:3500/video_example.srt</sec:CaptionInfo><sec:CaptionInfoEx sec:type="srt">http://192.168.88.250:3500/video_example.srt</sec:CaptionInfoEx><dc:title>video 'example'.mp4</dc:title><upnp:class>object.item.videoItem.movie</upnp:class><res protocolInfo="http-get:*:video/mp4:` + contentFeatures + `">http://192.168.88.250:3500/video%20%26%20%27example%27.mp4</res><res protocolInfo="http-get:*:text/srt:*">http://192.168.88.250:3500/video_example.srt</res></item></DIDL-Lite>` out, err := setNextAVTransportSoapBuild(tc.tv, false) if err != nil { t.Fatalf("%s: Failed to call setNextAVTransportSoapBuild due to %s", tc.name, err.Error()) } if string(out) != want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, want) } }) } } func TestSetMuteSoapBuild(t *testing.T) { tt := []struct { name string input string want string }{ { `setMuteSoapBuild Test #1`, "1", `0Master1`, }, { `setMuteSoapBuild Test #2`, "0", `0Master0`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := setMuteSoapBuild(tc.input) if err != nil { t.Fatalf("%s: Failed to call setMuteSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestGetVolumeSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `getVolumeSoapBuild Test #1`, `0Master`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := getVolumeSoapBuild() if err != nil { t.Fatalf("%s: Failed to call setMuteSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestPlaySoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `playSoapBuild Test #1`, `01`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := playSoapBuild() if err != nil { t.Fatalf("%s: Failed to call playSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestStopSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `stopSoapBuild Test #1`, `01`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := stopSoapBuild() if err != nil { t.Fatalf("%s: Failed to call stopSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestPauseSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `pauseSoapBuild Test #1`, `01`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := pauseSoapBuild() if err != nil { t.Fatalf("%s: Failed to call pauseSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestGetMuteSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `getMuteSoapBuild Test #1`, `0Master`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := getMuteSoapBuild() if err != nil { t.Fatalf("%s: Failed to call getMuteSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestSetVolumeSoapBuild(t *testing.T) { tt := []struct { name string intput string want string }{ { `setVolumeSoapBuild Test #1`, `100`, `0Master100`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := setVolumeSoapBuild(tc.intput) if err != nil { t.Fatalf("%s: Failed to call setVolumeSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestGetTransportInfoSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `getTransportInfoSoapBuildTest #1`, `0`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := getTransportInfoSoapBuild() if err != nil { t.Fatalf("%s: Failed to call getTransportInfoSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestGetPositionInfoSoapBuild(t *testing.T) { tt := []struct { name string want string }{ { `getPositionInfoSoapBuildTest #1`, `0`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := getPositionInfoSoapBuild() if err != nil { t.Fatalf("%s: Failed to call getPositionInfoSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } } func TestSeekSoapBuild(t *testing.T) { tt := []struct { name string target string want string }{ { `seekSoapBuildTest #1`, "00:01:30", `0REL_TIME00:01:30`, }, } for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { out, err := seekSoapBuild(tc.target) if err != nil { t.Fatalf("%s: Failed to call seekSoapBuild due to %s", tc.name, err.Error()) } if string(out) != tc.want { t.Fatalf("%s: got: %s, want: %s.", tc.name, out, tc.want) } }) } }