diff options
author | Jens Georg <mail@jensge.org> | 2020-05-05 22:35:53 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2020-05-31 16:57:51 +0200 |
commit | 3f02cedf5760d76d2557143d61672b07501e1cf5 (patch) | |
tree | 1623b2dc4add83c604d8ab9aa95717c3c4882a4b /tests | |
parent | b3a208d9a8f36d8f8acf10c7f9d841d36c7b4487 (diff) | |
download | rygel-3f02cedf5760d76d2557143d61672b07501e1cf5.tar.gz |
test: Re-add time-seek test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 12 | ||||
l--------- | tests/time-seek/rygel-http-seek.vala | 1 | ||||
l--------- | tests/time-seek/rygel-http-time-seek-request.vala | 1 | ||||
-rw-r--r-- | tests/time-seek/rygel-http-time-seek-test.vala | 97 |
4 files changed, 111 insertions, 0 deletions
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 |