[rygel] tests: Unit test for HTTPByteSeek
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] tests: Unit test for HTTPByteSeek
- Date: Sat, 20 Mar 2010 23:21:47 +0000 (UTC)
commit 57bb1a848a000361dd335e0d1db20cfcc816298f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Mar 19 20:24:57 2010 +0200
tests: Unit test for HTTPByteSeek
tests/Makefile.am | 9 ++-
tests/rygel-http-byte-seek-test.vala | 145 ++++++++++++++++++++++++++++++
tests/rygel-http-byte-seek.vala | 1 +
tests/rygel-http-seek_live-response.vala | 1 +
4 files changed, 154 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6f77412..af9bc57 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,7 +27,8 @@ AM_VALAFLAGS = --disable-warnings --thread \
check_PROGRAMS = rygel-http-item-uri-test \
rygel-http-response-test \
- rygel-live-response-test
+ rygel-live-response-test \
+ rygel-http-byte-seek-test
TESTS = $(check_PROGRAMS)
rygel_http_item_uri_test_SOURCES = rygel-http-item-uri-test.vala \
@@ -41,5 +42,9 @@ rygel_live_response_test_SOURCES = rygel-live-response-test.vala \
rygel-live-response.vala \
rygel-http-response_live-response.vala \
rygel-state-machine_live-response.vala \
- rygel-http-seek.vala \
+ rygel-http-seek_live-response.vala \
rygel-gst-utils.vala
+
+rygel_http_byte_seek_test_SOURCES = rygel-http-byte-seek-test.vala \
+ rygel-http-byte-seek.vala \
+ rygel-http-seek.vala
diff --git a/tests/rygel-http-byte-seek-test.vala b/tests/rygel-http-byte-seek-test.vala
new file mode 100644
index 0000000..12e2c14
--- /dev/null
+++ b/tests/rygel-http-byte-seek-test.vala
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshan ali nokia com>
+ * <zeeshanak gnome org>
+ *
+ * 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.
+ */
+
+private errordomain Rygel.TestError {
+ SKIP
+}
+
+private class Rygel.HTTPIdentityHandler : GLib.Object {}
+
+private class Rygel.MediaItem : GLib.Object {
+ public int64 size = 1024;
+}
+
+private class Rygel.Thumbnail : GLib.Object {
+ public int64 size = 1024;
+}
+
+private class Rygel.HTTPGet : GLib.Object {
+ public const string ITEM_URI = "http://DoesntMatterWhatThisIs";
+
+ public Soup.Message msg;
+ public MediaItem item;
+ public Thumbnail thumbnail;
+
+ public HTTPIdentityHandler handler;
+
+ public HTTPGet () {
+ this.msg = new Soup.Message ("HTTP", ITEM_URI);
+ this.item = new MediaItem ();
+ this.handler = new HTTPIdentityHandler ();
+ }
+
+ public HTTPGet.seek_start (int64 start) {
+ this ();
+
+ this.add_headers (start, -1);
+ }
+
+ public HTTPGet.seek_stop (int64 stop) {
+ this ();
+
+ this.add_headers (0, stop);
+ }
+
+ public HTTPGet.seek_start_stop (int64 start, int64 stop) {
+ this ();
+
+ this.add_headers (start, stop);
+ }
+
+ private void add_headers (int64 start, int64 stop) {
+ this.msg.request_headers.set_range (start, stop);
+ }
+}
+
+private class Rygel.HTTPByteSeekTest : GLib.Object {
+ public static int main (string[] args) {
+ try {
+ var test = new HTTPByteSeekTest ();
+
+ test.run ();
+ } catch (TestError.SKIP error) {
+ return 77;
+ } catch (Error error) {
+ critical ("%s", error.message);
+
+ return -1;
+ }
+
+ return 0;
+ }
+
+ public void run () throws HTTPSeekError {
+ this.test_no_seek ();
+ this.test_start_only_seek ();
+ this.test_stop_only_seek ();
+ this.test_start_stop_seek ();
+ }
+
+ public void test_no_seek () throws HTTPSeekError {
+ var request = new HTTPGet ();
+
+ this.test_seek (request, 0, request.item.size - 1);
+ }
+
+ public void test_start_only_seek () throws HTTPSeekError {
+ var request = new HTTPGet.seek_start (128);
+
+ this.test_seek (request, 128, request.item.size - 1);
+ }
+
+ public void test_stop_only_seek () throws HTTPSeekError {
+ var request = new HTTPGet.seek_stop (128);
+
+ this.test_seek (request, 0, 128);
+ }
+
+ public void test_start_stop_seek () throws HTTPSeekError {
+ var request = new HTTPGet.seek_start_stop (128, 256);
+
+ this.test_seek (request, 128, 256);
+ }
+
+ private void test_seek (HTTPGet request,
+ int64 start,
+ int64 stop) throws HTTPSeekError {
+ assert (HTTPByteSeek.needed (request));
+
+ var seek = new HTTPByteSeek (request);
+ seek.add_response_headers ();
+
+ assert (seek != null);
+ assert (seek.start == start);
+ assert (seek.stop == stop);
+ assert (seek.length == request.item.size);
+
+ var header = request.msg.response_headers.get ("Accept-Ranges");
+ assert (header == "bytes");
+ header = request.msg.response_headers.get ("Content-Range");
+ assert (header != null);
+
+ assert (request.msg.response_headers.get_content_length () ==
+ request.item.size);
+ }
+}
diff --git a/tests/rygel-http-byte-seek.vala b/tests/rygel-http-byte-seek.vala
new file mode 120000
index 0000000..c394bbd
--- /dev/null
+++ b/tests/rygel-http-byte-seek.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-byte-seek.vala
\ No newline at end of file
diff --git a/tests/rygel-http-seek_live-response.vala b/tests/rygel-http-seek_live-response.vala
new file mode 120000
index 0000000..343aaf6
--- /dev/null
+++ b/tests/rygel-http-seek_live-response.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-seek.vala
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]