[rygel] test: Add unit test for HTTPTimeSeek



commit ec3ec710b9cb3be604e094e2209e0faa98ea725d
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue May 11 15:40:06 2010 +0300

    test: Add unit test for HTTPTimeSeek

 tests/Makefile.am                    |    8 ++-
 tests/rygel-http-seek_time-seek.vala |    1 +
 tests/rygel-http-time-seek-test.vala |  186 ++++++++++++++++++++++++++++++++++
 tests/rygel-http-time-seek.vala      |    1 +
 4 files changed, 195 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index af9bc57..e014b1e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,9 @@ AM_VALAFLAGS = --disable-warnings --thread \
 check_PROGRAMS = rygel-http-item-uri-test \
 		 rygel-http-response-test \
 		 rygel-live-response-test \
-		 rygel-http-byte-seek-test
+		 rygel-http-byte-seek-test \
+		 rygel-http-time-seek-test
+
 TESTS = $(check_PROGRAMS)
 
 rygel_http_item_uri_test_SOURCES = rygel-http-item-uri-test.vala \
@@ -48,3 +50,7 @@ rygel_live_response_test_SOURCES = rygel-live-response-test.vala \
 rygel_http_byte_seek_test_SOURCES = rygel-http-byte-seek-test.vala \
 				    rygel-http-byte-seek.vala \
 				    rygel-http-seek.vala
+
+rygel_http_time_seek_test_SOURCES = rygel-http-time-seek-test.vala \
+				    rygel-http-time-seek.vala \
+				    rygel-http-seek_time-seek.vala
diff --git a/tests/rygel-http-seek_time-seek.vala b/tests/rygel-http-seek_time-seek.vala
new file mode 120000
index 0000000..343aaf6
--- /dev/null
+++ b/tests/rygel-http-seek_time-seek.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-seek.vala
\ No newline at end of file
diff --git a/tests/rygel-http-time-seek-test.vala b/tests/rygel-http-time-seek-test.vala
new file mode 100644
index 0000000..ce18657
--- /dev/null
+++ b/tests/rygel-http-time-seek-test.vala
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+using Gst;
+
+private errordomain Rygel.TestError {
+    SKIP
+}
+
+private class Rygel.HTTPTranscodeHandler : GLib.Object {}
+
+private class Rygel.MediaItem : GLib.Object {
+    public int64 duration = 2048;
+    public int64 size = -1;
+
+    public virtual bool should_stream () {
+        return true;
+    }
+}
+
+private class Rygel.Thumbnail : GLib.Object {}
+private class Rygel.Subtitle : GLib.Object {}
+
+private class Rygel.HTTPGet : GLib.Object {
+    public const string ITEM_URI = "http://DoesntMatterWhatThisIs";;
+
+    public Soup.Message msg;
+    public MediaItem item;
+    public Thumbnail thumbnail;
+    public Subtitle subtitle;
+
+    public HTTPTranscodeHandler handler;
+
+    public HTTPGet (Thumbnail? thumbnail, Subtitle? subtitle) {
+        this.msg = new Soup.Message ("HTTP", ITEM_URI);
+        this.item = new MediaItem ();
+        this.handler = new HTTPTranscodeHandler ();
+        this.thumbnail = thumbnail;
+        this.subtitle = subtitle;
+    }
+
+    public HTTPGet.seek_start (int64      start,
+                               Thumbnail? thumbnail,
+                               Subtitle?  subtitle) {
+        this (thumbnail, subtitle);
+
+        this.add_headers (start, -1);
+    }
+
+    public HTTPGet.seek_stop (int64      stop,
+                              Thumbnail? thumbnail,
+                              Subtitle?  subtitle) {
+        this (thumbnail, subtitle);
+
+        this.add_headers (0, stop);
+    }
+
+    public HTTPGet.seek_start_stop (int64      start,
+                                    int64      stop,
+                                    Thumbnail? thumbnail,
+                                    Subtitle?  subtitle) {
+        this (thumbnail, subtitle);
+
+        this.add_headers (start, stop);
+    }
+
+    private void add_headers (int64 start, int64 stop) requires (start >= 0) {
+        var stop_str = (stop > 0)? stop.to_string (): "";
+        var range = "npt=" + start.to_string () + "-" + stop_str;
+        this.msg.request_headers.append ("TimeSeekRange.dlna.org", range);
+    }
+}
+
+private class Rygel.HTTPTimeSeekTest : GLib.Object {
+    private Regex range_regex;
+
+    public static int main (string[] args) {
+        try {
+            var test = new HTTPTimeSeekTest ();
+
+            test.run ();
+        } catch (TestError.SKIP error) {
+            return 77;
+        } catch (Error error) {
+            critical ("%s", error.message);
+
+            return -1;
+        }
+
+        return 0;
+    }
+
+    public void run () throws HTTPSeekError {
+        var thumbnails = new Thumbnail[] { null, new Thumbnail () };
+        var subtitles = new Subtitle[] { null, new Subtitle () };
+
+        foreach (var thumbnail in thumbnails) {
+            foreach (var subtitle in subtitles) {
+                this.test_no_seek (thumbnail, subtitle);
+                this.test_start_only_seek (thumbnail, subtitle);
+                this.test_stop_only_seek (thumbnail, subtitle);
+                this.test_start_stop_seek (thumbnail, subtitle);
+            }
+        }
+    }
+
+    private HTTPTimeSeekTest () {
+        var expression = "npt=[0-9]+\\.[0-9][0-9]-" +
+                         "[0-9]+\\.[0-9][0-9]/" +
+                         "[0-9]+\\.[0-9][0-9]";
+        this.range_regex = new Regex (expression, RegexCompileFlags.CASELESS);
+    }
+
+    private void test_no_seek (Thumbnail? thumbnail,
+                               Subtitle?  subtitle) throws HTTPSeekError {
+        var request = new HTTPGet (thumbnail, subtitle);
+
+        this.test_seek (request, 0, request.item.duration - 1);
+    }
+
+    private void test_start_only_seek (Thumbnail? thumbnail,
+                                       Subtitle?  subtitle)
+                                       throws HTTPSeekError {
+        var request = new HTTPGet.seek_start (128, thumbnail, subtitle);
+
+        this.test_seek (request, 128, request.item.duration - 1);
+    }
+
+    private void test_stop_only_seek (Thumbnail? thumbnail,
+                                      Subtitle?  subtitle)
+                                      throws HTTPSeekError {
+        var request = new HTTPGet.seek_stop (128, thumbnail, subtitle);
+
+        this.test_seek (request, 0, 128);
+    }
+
+    private void test_start_stop_seek (Thumbnail? thumbnail,
+                                       Subtitle?  subtitle)
+                                       throws HTTPSeekError {
+        var request = new HTTPGet.seek_start_stop (128,
+                                                   256,
+                                                   thumbnail,
+                                                   subtitle);
+
+        this.test_seek (request, 128, 256);
+    }
+
+    private void test_seek (HTTPGet request,
+                            int64   start,
+                            int64   stop) throws HTTPSeekError {
+        assert (HTTPTimeSeek.needed (request));
+
+        var seek = new HTTPTimeSeek (request);
+        seek.add_response_headers ();
+
+        assert (seek != null);
+        assert (seek.start == start * SECOND);
+        assert (seek.stop == stop * SECOND);
+        assert (seek.length == request.item.duration * SECOND);
+
+        var header = request.msg.response_headers.get (
+                                        "TimeSeekRange.dlna.org");
+        assert (header != null);
+        assert (this.range_regex.match (header));
+    }
+}
diff --git a/tests/rygel-http-time-seek.vala b/tests/rygel-http-time-seek.vala
new file mode 120000
index 0000000..48b688b
--- /dev/null
+++ b/tests/rygel-http-time-seek.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-http-time-seek.vala
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]