[rygel] tests: Unit test for HTTPGet
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] tests: Unit test for HTTPGet
- Date: Wed, 9 Jun 2010 14:53:43 +0000 (UTC)
commit 566d9fd08b879d2fa399a889154411e1e457a2d1
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Jun 4 21:05:49 2010 +0300
tests: Unit test for HTTPGet
po/POTFILES.skip | 5 +
tests/Makefile.am | 12 +-
tests/rygel-http-byte-seek_http-get.vala | 1 +
tests/rygel-http-get-test.vala | 297 ++++++++++++++++++++++++++++++
tests/rygel-http-get.vala | 1 +
tests/rygel-http-item-uri_http-get.vala | 1 +
tests/rygel-http-request_http-get.vala | 1 +
tests/rygel-http-seek_http-get.vala | 1 +
tests/rygel-http-time-seek_http-get.vala | 1 +
tests/rygel-state-machine_http-get.vala | 1 +
10 files changed, 320 insertions(+), 1 deletions(-)
---
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index bff06e3..ca06323 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -80,3 +80,8 @@ tests/rygel-http-item-uri.c
tests/rygel-http-time-seek.c
tests/rygel-live-response.c
tests/rygel-seekable-response.c
+tests/rygel-http-byte-seek_http-get.c
+tests/rygel-http-get.c
+tests/rygel-http-item-uri_http-get.c
+tests/rygel-http-request_http-get.c
+tests/rygel-http-time-seek_http-get.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7350a03..e6e49a0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,7 +29,8 @@ check_PROGRAMS = rygel-http-item-uri-test \
rygel-live-response-test \
rygel-seekable-response-test \
rygel-http-byte-seek-test \
- rygel-http-time-seek-test
+ rygel-http-time-seek-test \
+ rygel-http-get-test
TESTS = $(check_PROGRAMS)
@@ -58,3 +59,12 @@ rygel_http_byte_seek_test_SOURCES = rygel-http-byte-seek-test.vala \
rygel_http_time_seek_test_SOURCES = rygel-http-time-seek-test.vala \
rygel-http-time-seek.vala \
rygel-http-seek_time-seek.vala
+
+rygel_http_get_test_SOURCES = rygel-http-get-test.vala \
+ rygel-http-get.vala \
+ rygel-http-request_http-get.vala \
+ rygel-http-item-uri_http-get.vala \
+ rygel-state-machine_http-get.vala \
+ rygel-http-time-seek_http-get.vala \
+ rygel-http-byte-seek_http-get.vala \
+ rygel-http-seek_http-get.vala
diff --git a/tests/rygel-http-byte-seek_http-get.vala b/tests/rygel-http-byte-seek_http-get.vala
new file mode 120000
index 0000000..c394bbd
--- /dev/null
+++ b/tests/rygel-http-byte-seek_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-byte-seek.vala
\ No newline at end of file
diff --git a/tests/rygel-http-get-test.vala b/tests/rygel-http-get-test.vala
new file mode 100644
index 0000000..2437602
--- /dev/null
+++ b/tests/rygel-http-get-test.vala
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * <zeeshan ali nokia com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Soup;
+using Gee;
+
+public errordomain Rygel.TestError {
+ SKIP = 77,
+ TIMEOUT
+}
+
+public class Rygel.HTTPGetTest : GLib.Object {
+ protected HTTPServer server;
+ protected HTTPClient client;
+
+ private bool server_done;
+ private bool client_done;
+
+ private MainLoop main_loop;
+
+ private Error error;
+
+ public static int main (string[] args) {
+ try {
+ var test = new HTTPGetTest ();
+
+ test.run ();
+ } catch (TestError.SKIP error) {
+ return error.code;
+ } catch (Error error) {
+ critical ("%s", error.message);
+
+ return -1;
+ }
+
+ return 0;
+ }
+
+ public HTTPGetTest () throws Error {
+ this.server = new HTTPServer ();
+ this.client = new HTTPClient (this.server.context,
+ this.server.uri);
+ this.main_loop = new MainLoop (null, false);
+ }
+
+ public virtual void run () throws Error {
+ Timeout.add_seconds (3, this.on_timeout);
+ this.server.message_received.connect (this.on_message_received);
+ this.client.completed.connect (this.on_client_completed);
+
+ this.client.run.begin ();
+
+ this.main_loop.run ();
+
+ if (this.error != null) {
+ throw this.error;
+ }
+ }
+
+ private HTTPRequest create_request (Soup.Message msg) throws Error {
+ return new HTTPGet (this.server,
+ this.server.context.server,
+ msg);
+ }
+
+ private void on_client_completed (StateMachine client) {
+ if (this.server_done) {
+ this.main_loop.quit ();
+ }
+
+ this.client_done = true;
+ }
+
+ private void on_message_received (HTTPServer server,
+ Soup.Message msg) {
+ this.handle_client_message.begin (msg);
+ }
+
+ private async void handle_client_message (Soup.Message msg) {
+ try {
+ var request = this.create_request (msg);
+
+ yield request.run ();
+
+ assert ((request as HTTPGet).item != null);
+
+ if (this.client_done) {
+ this.main_loop.quit ();
+ }
+
+ this.server_done = true;
+ } catch (Error error) {
+ this.error = error;
+ this.main_loop.quit ();
+
+ return;
+ }
+ }
+
+ private bool on_timeout () {
+ this.error = new TestError.TIMEOUT ("Timeout");
+ this.main_loop.quit ();
+
+ return false;
+ }
+}
+
+public class Rygel.HTTPServer : GLib.Object {
+ private const string SERVER_PATH = "/RygelHTTPServer/Rygel/Test";
+ public string path_root {
+ get {
+ return SERVER_PATH;
+ }
+ }
+
+ public MediaContainer root_container;
+ public GUPnP.Context context;
+
+ public string uri {
+ owned get {
+ var item_uri = new HTTPItemURI (this.root_container.ITEM_ID,
+ this);
+
+ return item_uri.to_string ();
+ }
+ }
+
+ public signal void message_received (Soup.Message message);
+
+ public HTTPServer () throws TestError {
+ try {
+ this.context = new GUPnP.Context (null, "lo", 0);
+ } catch (Error error) {
+ throw new TestError.SKIP ("Network context not available");
+ }
+
+ assert (this.context != null);
+ assert (this.context.host_ip != null);
+ assert (this.context.port > 0);
+
+ this.context.server.add_handler (SERVER_PATH, this.server_cb);
+
+ this.root_container = new MediaContainer ();
+ }
+
+ private void server_cb (Server server,
+ Soup.Message msg,
+ string path,
+ HashTable? query,
+ ClientContext client) {
+ this.context.server.pause_message (msg);
+ this.message_received (msg);
+ }
+
+ public Transcoder get_transcoder (string target) throws Error {
+ return new Transcoder ();
+ }
+}
+
+public class Rygel.HTTPClient : GLib.Object, StateMachine {
+ public GUPnP.Context context;
+ public Soup.Message msg;
+
+ public Cancellable cancellable { get; set; }
+
+ public HTTPClient (GUPnP.Context context,
+ string uri) {
+ this.context = context;
+
+ this.msg = new Soup.Message ("GET", uri);
+ assert (this.msg != null);
+ }
+
+ public async void run () {
+ SourceFunc run_continue = run.callback;
+
+ this.context.session.queue_message (this.msg, (session, msg) => {
+ run_continue ();
+ });
+
+ yield;
+
+ this.completed ();
+ }
+}
+
+public class Rygel.MediaContainer : Rygel.MediaObject {
+ public const string ITEM_ID = "TestItem";
+
+ public async MediaObject? find_object (string item_id,
+ Cancellable? cancellable)
+ throws Error {
+ SourceFunc find_object_continue = find_object.callback;
+ Idle.add (() => {
+ find_object_continue ();
+
+ return false;
+ });
+
+ yield;
+
+ if (item_id == ITEM_ID) {
+ return new MediaItem ();
+ } else {
+ return null;
+ }
+ }
+}
+
+internal abstract class Rygel.HTTPGetHandler {
+ public HTTPResponse render_body (HTTPGet get_request) {
+ return new HTTPResponse (get_request);
+ }
+
+ public void add_response_headers (HTTPGet get_request) {}
+}
+
+internal class Rygel.HTTPTranscodeHandler : Rygel.HTTPGetHandler {
+ public HTTPTranscodeHandler (Transcoder transcoder,
+ Cancellable cancellable) {}
+}
+
+internal class Rygel.HTTPIdentityHandler : Rygel.HTTPGetHandler {
+ public HTTPIdentityHandler (Cancellable cancellable) {}
+}
+
+public class Rygel.MediaItem : Rygel.MediaObject {
+ public long size = 1024;
+ public long duration = 1024;
+ public ArrayList<Subtitle> subtitles = new ArrayList<Subtitle> ();
+ public ArrayList<Thumbnail> thumbnails = new ArrayList<Thumbnail> ();
+
+ public bool should_stream () {
+ return true;
+ }
+}
+
+public class Rygel.Thumbnail {
+ public long size = 1024;
+}
+
+public class Rygel.Subtitle {
+ public long size = 1024;
+}
+
+internal class Rygel.HTTPResponse : Rygel.StateMachine, GLib.Object {
+ public abstract Cancellable cancellable { get; set; }
+
+ private Soup.Message msg;
+ private Soup.Server server;
+
+ public HTTPResponse (HTTPGet get_request) {
+ this.msg = get_request.msg;
+ this.server = get_request.server;
+ }
+
+ public async void run () {
+ SourceFunc run_continue = run.callback;
+
+ Idle.add (() => {
+ run_continue ();
+
+ return false;
+ });
+
+ yield;
+
+ this.msg.set_status (Soup.KnownStatusCode.OK);
+ this.server.unpause_message (msg);
+
+ this.completed ();
+ }
+}
+
+
+public class Rygel.Transcoder {}
+public class Rygel.MediaObject {}
diff --git a/tests/rygel-http-get.vala b/tests/rygel-http-get.vala
new file mode 120000
index 0000000..1bcf54b
--- /dev/null
+++ b/tests/rygel-http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-get.vala
\ No newline at end of file
diff --git a/tests/rygel-http-item-uri_http-get.vala b/tests/rygel-http-item-uri_http-get.vala
new file mode 120000
index 0000000..b6cf2d8
--- /dev/null
+++ b/tests/rygel-http-item-uri_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-item-uri.vala
\ No newline at end of file
diff --git a/tests/rygel-http-request_http-get.vala b/tests/rygel-http-request_http-get.vala
new file mode 120000
index 0000000..611f7e5
--- /dev/null
+++ b/tests/rygel-http-request_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-request.vala
\ No newline at end of file
diff --git a/tests/rygel-http-seek_http-get.vala b/tests/rygel-http-seek_http-get.vala
new file mode 120000
index 0000000..343aaf6
--- /dev/null
+++ b/tests/rygel-http-seek_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-seek.vala
\ No newline at end of file
diff --git a/tests/rygel-http-time-seek_http-get.vala b/tests/rygel-http-time-seek_http-get.vala
new file mode 120000
index 0000000..48b688b
--- /dev/null
+++ b/tests/rygel-http-time-seek_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-time-seek.vala
\ No newline at end of file
diff --git a/tests/rygel-state-machine_http-get.vala b/tests/rygel-state-machine_http-get.vala
new file mode 120000
index 0000000..5063d68
--- /dev/null
+++ b/tests/rygel-state-machine_http-get.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-state-machine.vala
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]