[rygel/wip/tracker-3.0: 17/25] test: Re-add time-seek test



commit 29f9a592cd364cdf2ee1df35cddd328d73dfefec
Author: Jens Georg <mail jensge org>
Date:   Tue May 5 22:35:53 2020 +0200

    test: Re-add time-seek test

 tests/meson.build                                 | 12 +++
 tests/time-seek/rygel-http-seek.vala              |  1 +
 tests/time-seek/rygel-http-time-seek-request.vala |  1 +
 tests/time-seek/rygel-http-time-seek-test.vala    | 97 +++++++++++++++++++++++
 4 files changed, 111 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 480f9d1d..9cc00e38 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -56,6 +56,16 @@ playbin_renderer_test = executable(
     dependencies : [gstreamer, rygel_core, rygel_renderer, rygel_renderer_gst]
 )
 
+http_time_seek_test = executable(
+    'rygel-http-time-seek-test',
+    files(
+        'time-seek/rygel-http-seek.vala',
+        'time-seek/rygel-http-time-seek-request.vala',
+        'time-seek/rygel-http-time-seek-test.vala'
+    ),
+    dependencies : [glib, soup]
+)
+
 test('rygel-searchable-container-test', searchable_container_test)
 test('rygel-object-creator-test', object_creator_test)
 test('rygel-regression-test', regression_test)
@@ -65,3 +75,5 @@ test('rygel-playbin-renderer-test', playbin_renderer_test)
 
 # Up the timeout, the test itself is waiting 10s per round for changes, doing 4 rounds
 test('rygel-user-config-test', user_config_test, timeout : 50)
+
+test('rygel-http-time-seek-test', http_time_seek_test)
\ No newline at end of file
diff --git a/tests/time-seek/rygel-http-seek.vala b/tests/time-seek/rygel-http-seek.vala
new file mode 120000
index 00000000..91906117
--- /dev/null
+++ b/tests/time-seek/rygel-http-seek.vala
@@ -0,0 +1 @@
+../../src/librygel-server/rygel-http-seek.vala
\ No newline at end of file
diff --git a/tests/time-seek/rygel-http-time-seek-request.vala 
b/tests/time-seek/rygel-http-time-seek-request.vala
new file mode 120000
index 00000000..88689621
--- /dev/null
+++ b/tests/time-seek/rygel-http-time-seek-request.vala
@@ -0,0 +1 @@
+../../src/librygel-server/rygel-http-time-seek-request.vala
\ No newline at end of file
diff --git a/tests/time-seek/rygel-http-time-seek-test.vala b/tests/time-seek/rygel-http-time-seek-test.vala
new file mode 100644
index 00000000..c6715711
--- /dev/null
+++ b/tests/time-seek/rygel-http-time-seek-test.vala
@@ -0,0 +1,97 @@
+public class PlaySpeed : Object {
+    public double speed = 1.0;
+
+    public bool is_positive () { return this.speed >= 0; }
+    public bool is_normal_rate () { return this.speed == 1.0; }
+}
+
+public class HTTPGetHandler : Object {
+    public int64 get_resource_duration () {
+        return 0;
+    }
+
+    public bool supports_time_seek () { return true; }
+}
+
+public class ClientHacks : Object {
+    public static ClientHacks? create (Soup.Message message) throws Error {
+        throw new NumberParserError.INVALID ("");
+    }
+
+    public bool force_seek () { return false; }
+}
+
+void test_time_seek_malformed_header () {
+    // Mock data
+    var message = new Soup.Message ("GET", "http://localhost";);
+    var handler = new HTTPGetHandler ();
+
+    // Test without the header
+    try {
+        var request = new Rygel.HTTPTimeSeekRequest (message, handler, null);
+        assert_not_reached ();
+    } catch (Rygel.HTTPSeekRequestError e) {
+        // Pass - we only expect a HTTPSeekRequestError
+        assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
+    } catch (Error e) {
+        assert_not_reached ();
+    }
+
+    // Test empty header
+    message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER, "");
+    try {
+        var request = new Rygel.HTTPTimeSeekRequest (message, handler, null);
+        assert_not_reached ();
+    } catch (Rygel.HTTPSeekRequestError e) {
+        // Pass - we only expect a HTTPSeekRequestError
+        assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
+    } catch (Error e) {
+        assert_not_reached ();
+    }
+
+    // Test empty header
+    message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER, "npt=kjalsjd lsdjldskj 
lkfdsj ");
+    try {
+        var request = new Rygel.HTTPTimeSeekRequest (message, handler, null);
+        assert_not_reached ();
+    } catch (Rygel.HTTPSeekRequestError e) {
+        // Pass - we only expect a HTTPSeekRequestError
+        assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
+    } catch (Error e) {
+        assert_not_reached ();
+    }
+
+    // Must not have white-spaces before npt=
+    message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER,
+                                     "         npt=0.000-");
+    try {
+        var request = new Rygel.HTTPTimeSeekRequest (message, handler, null);
+        assert_not_reached ();
+    } catch (Rygel.HTTPSeekRequestError e) {
+        // Pass - we only expect a HTTPSeekRequestError
+        assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
+    } catch (Error e) {
+        assert_not_reached ();
+    }
+
+    // Must not have white-spaces in the time
+    message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER,
+                                     "npt = 00 : 05 : 35.3-00");
+    try {
+        var request = new Rygel.HTTPTimeSeekRequest (message, handler, null);
+        assert_not_reached ();
+    } catch (Rygel.HTTPSeekRequestError e) {
+        // Pass - we only expect a HTTPSeekRequestError
+        assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
+    } catch (Error e) {
+        assert_not_reached ();
+    }
+}
+
+int main(string[] args) {
+    Intl.setlocale (LocaleCategory.ALL, "C");
+    Test.init (ref args);
+
+    Test.add_func ("/server/time-seek/request", test_time_seek_malformed_header);
+    return Test.run ();
+}
\ No newline at end of file


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