2 * Copyright (C) 2010 Nokia Corporation.
4 * Author: Zeeshan Ali (Khattak) <zeeshan.ali@nokia.com>
5 * <zeeshanak@gnome.org>
7 * This file is part of Rygel.
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 private errordomain Rygel.HTTPRequestError {
27 UNACCEPTABLE = Soup.Status.NOT_ACCEPTABLE,
28 BAD_REQUEST = Soup.Status.BAD_REQUEST,
29 NOT_FOUND = Soup.Status.NOT_FOUND
32 private errordomain Rygel.TestError {
36 private class Rygel.Transcoder : GLib.Object {
37 public string extension { get; protected set; }
39 public Transcoder (string extension) {
40 this.extension = extension;
44 private class Rygel.HTTPServer : GLib.Object {
45 private const string SERVER_PATH = "/Test";
47 public string path_root { get; private set; }
49 public GUPnP.Context context;
51 public HTTPServer () throws TestError {
52 this.path_root = SERVER_PATH;
55 this.context = new GUPnP.Context (null, "lo", 0);
56 } catch (Error error) {
57 throw new TestError.SKIP ("Network context not available");
60 assert (this.context != null);
61 assert (this.context.host_ip != null);
62 assert (this.context.port > 0);
65 public Transcoder get_transcoder (string target) throws Error {
66 if (target == "MP3") {
67 return new Transcoder ("mp3");
69 throw new HTTPRequestError.NOT_FOUND (
70 "No transcoder available for target format '%s'",
75 private class Rygel.MediaObject : GLib.Object {
79 private class Rygel.MediaItem : Rygel.MediaObject {
80 public ArrayList<string> uris = new ArrayList<string> ();
81 public string mime_type;
84 private class Rygel.Thumbnail {
85 public string file_extension;
88 private class Rygel.VisualItem : MediaItem {
89 public ArrayList<Thumbnail> thumbnails = new ArrayList<Thumbnail> ();
92 private class Rygel.Subtitle : GLib.Object {
93 public string caption_type;
96 private class Rygel.VideoItem : VisualItem {
97 public ArrayList<Subtitle> subtitles = new ArrayList<Subtitle> ();
100 private class Rygel.MusicItem : MediaItem {
101 public Thumbnail album_art;
104 private class Rygel.HTTPItemURITest : GLib.Object {
105 private const int THUMBNAIL_INDEX = 1;
106 private const int SUBTITLE_INDEX = 1;
107 private const string TRANSCODE_TARGET = "MP3";
108 private VisualItem item = new VisualItem ();
109 private HTTPServer server;
111 public static int main (string[] args) {
113 var test = new HTTPItemURITest ();
116 } catch (TestError.SKIP error) {
118 } catch (Error error) {
119 critical ("%s", error.message);
127 public void run () throws Error {
128 Thumbnail thumb = new Thumbnail ();
130 thumb.file_extension = "png";
131 this.item.thumbnails.add (thumb);
132 this.item.id = "HELLO";
133 this.item.uris.add ("foo.mp3");
134 this.item.mime_type = "audio/mp3";
136 var uris = new HTTPItemURI[] {
137 this.test_construction (),
138 this.test_construction_with_thumbnail (),
139 this.test_construction_with_subtitle (),
140 this.test_construction_with_transcoder () };
142 foreach (var uri in uris) {
143 var str = this.test_to_string (uri);
144 this.test_construction_from_string (str);
146 this.test_error_construction ("/Ttt", Soup.Status.BAD_REQUEST);
149 private HTTPItemURITest () throws TestError {
150 this.server = new HTTPServer ();
153 private HTTPItemURI test_construction () {
154 var uri = new HTTPItemURI (this.item, this.server);
155 assert (uri != null);
160 private HTTPItemURI test_construction_with_subtitle () {
161 var uri = new HTTPItemURI (this.item,
165 assert (uri != null);
170 private HTTPItemURI test_construction_with_thumbnail () {
171 var uri = new HTTPItemURI (this.item,
174 assert (uri != null);
179 private HTTPItemURI test_construction_with_transcoder () {
180 var uri = new HTTPItemURI (this.item,
185 assert (uri != null);
190 private HTTPItemURI test_construction_from_string (string str)
192 var uri = new HTTPItemURI.from_string (str, this.server);
193 assert (uri != null);
194 assert (uri.to_string () == str);
199 private void test_error_construction (string str,
200 Soup.Status error_code) {
202 var uri = new HTTPItemURI.from_string (str, this.server);
203 assert (uri == null);
204 } catch (HTTPRequestError error) {
205 assert (error.code == error_code);
209 private string test_to_string (HTTPItemURI uri) {
210 var str = uri.to_string ();
211 assert (str != null);