From be8fefed0b2b354930b8be5be5645314e3ee5fcd Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Sat, 27 Feb 2016 00:48:20 +0100 Subject: tests: Enable SearchableContainer test Signed-off-by: Jens Georg --- tests/Makefile.am | 24 +-- tests/rygel-searchable-container-test.vala | 190 --------------------- .../rygel-searchable-container.vala | 1 + tests/searchable-container/test.vala | 190 +++++++++++++++++++++ 4 files changed, 203 insertions(+), 202 deletions(-) delete mode 100644 tests/rygel-searchable-container-test.vala create mode 120000 tests/searchable-container/rygel-searchable-container.vala create mode 100644 tests/searchable-container/test.vala (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 7393c90f..47db215c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,13 +8,13 @@ AUTOMAKE_OPTIONS = subdir-objects # rygel-http-time-seek-test \ # rygel-http-get-test \ # rygel-http-post-test \ -# rygel-searchable-container-test \ # rygel-user-config-test \ # rygel-regression \ # rygel-media-engine-test check_PROGRAMS = rygel-regression \ rygel-user-config-test \ + rygel-searchable-container-test \ rygel-object-creator-test TESTS = $(check_PROGRAMS) @@ -117,17 +117,17 @@ test_server_libs = \ #rygel_http_post_test_LDADD = \ # $(test_libs) # -#rygel_searchable_container_test_SOURCES = \ -# rygel-searchable-container.vala \ -# rygel-searchable-container-test.vala -#rygel_searchable_container_test_VALAFLAGS = \ -# $(test_valaflags) \ -# --pkg gupnp-av-1.0 -#rygel_searchable_container_test_CFLAGS = \ -# $(test_cflags) -#rygel_searchable_container_test_LDADD = \ -# $(test_libs) -# +rygel_searchable_container_test_SOURCES = \ + searchable-container/rygel-searchable-container.vala \ + searchable-container/test.vala +rygel_searchable_container_test_VALAFLAGS = \ + $(test_valaflags) \ + --pkg gupnp-av-1.0 +rygel_searchable_container_test_CFLAGS = \ + $(test_cflags) +rygel_searchable_container_test_LDADD = \ + $(test_libs) + rygel_object_creator_test_SOURCES = object-creator/test.vala \ object-creator/rygel-object-creator.vala \ object-creator/rygel-dlna-profile.vala \ diff --git a/tests/rygel-searchable-container-test.vala b/tests/rygel-searchable-container-test.vala deleted file mode 100644 index 55d5fe58..00000000 --- a/tests/rygel-searchable-container-test.vala +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2012 Jens Georg. - * - * Author: Jens Georg - * - * 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.1 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -public class RelationalExpression : SearchExpression { -} - -namespace SearchCriteriaOp { - public const string EQ = "="; -} - -public class SearchExpression : Object { - public string operand1; - public string operand2; - public string op; - - public bool satisfied_by (MediaObject object) { - return true; - } -} - -public class MediaObject : Object { -} - -public class MediaContainer : MediaObject { - public string sort_criteria = "+dc:title"; - public int child_count = 10; - public bool create_mode_enabled = false; - public int all_child_count { - get { return this.child_count; } - } - public async MediaObjects? get_children ( - uint offset, - uint max_count, - string sort_criteria, - Cancellable? cancellable) - throws Error { - Idle.add ( () => { get_children.callback (); return false; }); - yield; - - var result = new MediaObjects (); - for (int i = 0; i < 10; ++i) { - result.add (new MediaObject ()); - } - - return result; - } - - internal void check_search_expression (SearchExpression? expression) {} -} - -public class TestContainer : MediaContainer, Rygel.SearchableContainer { - public MainLoop loop; - public Gee.ArrayList search_classes { get; set; default = new - Gee.ArrayList ();} - - public async void test_search_no_limit () { - uint total_matches = 0; - - // check corners - try { - var result = yield search (null, 0, 0, out total_matches, "", null); - assert (total_matches == 10); - assert (result.size == 10); - } catch (GLib.Error error) { - assert_not_reached (); - } - - try { - var result = yield search (null, 10, 0, out total_matches, "", null); - assert (total_matches == 10); - assert (result.size == 0); - } catch (GLib.Error error) { - assert_not_reached (); - } - - for (int i = 1; i < 10; ++i) { - try { - var result = yield search (null, i, 0, out total_matches, "", null); - assert (total_matches == 10); - assert (result.size == 10 - i); - } catch (GLib.Error error) { - assert_not_reached (); - } - } - - this.loop.quit (); - } - - public async void test_search_with_limit () { - uint total_matches; - - // check corners - try { - var result = yield search (null, 0, 4, out total_matches, "", null); - assert (total_matches == 0); - assert (result.size == 4); - } catch (GLib.Error error) { - assert_not_reached (); - } - - try - { - var result = yield search (null, 10, 4, out total_matches, "", null); - assert (total_matches == 0); - assert (result.size == 0); - } catch (GLib.Error error) { - assert_not_reached (); - } - - for (int i = 1; i < 10; ++i) { - try { - var result = yield search (null, i, 3, out total_matches, "", null); - assert (total_matches == 0); - assert (result.size == int.min (10 - i, 3)); - } catch (GLib.Error error) { - assert_not_reached (); - } - } - - this.loop.quit (); - } - - /* TODO: This is just here to avoid a warning about - * serialize_search_parameters() not being used. - * How should this really be tested? - */ - public void test_serialization() { - var writer = new GUPnP.DIDLLiteWriter(null); - var didl_container = writer.add_container(); - serialize_search_parameters(didl_container); - } - - public async MediaObjects? search (SearchExpression? expression, - uint offset, - uint max_count, - out uint total_matches, - string sort_criteria, - Cancellable? cancellable) - throws Error { - return yield this.simple_search (expression, - offset, - max_count, - out total_matches, - sort_criteria ?? this.sort_criteria, - cancellable); - } - -} - -public class MediaObjects : Gee.ArrayList { - public override Gee.List? slice (int start, int stop) { - var slice = base.slice (start, stop); - var ret = new MediaObjects (); - - ret.add_all (slice); - - return ret; - } -} - -int main () -{ - var c = new TestContainer (); - c.loop = new MainLoop (); - c.test_search_no_limit.begin (); - c.loop.run (); - c.test_search_with_limit.begin (); - c.loop.run (); - - return 0; -} diff --git a/tests/searchable-container/rygel-searchable-container.vala b/tests/searchable-container/rygel-searchable-container.vala new file mode 120000 index 00000000..0401c6c4 --- /dev/null +++ b/tests/searchable-container/rygel-searchable-container.vala @@ -0,0 +1 @@ +../../src/librygel-server/rygel-searchable-container.vala \ No newline at end of file diff --git a/tests/searchable-container/test.vala b/tests/searchable-container/test.vala new file mode 100644 index 00000000..55d5fe58 --- /dev/null +++ b/tests/searchable-container/test.vala @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2012 Jens Georg. + * + * Author: Jens Georg + * + * 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.1 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +public class RelationalExpression : SearchExpression { +} + +namespace SearchCriteriaOp { + public const string EQ = "="; +} + +public class SearchExpression : Object { + public string operand1; + public string operand2; + public string op; + + public bool satisfied_by (MediaObject object) { + return true; + } +} + +public class MediaObject : Object { +} + +public class MediaContainer : MediaObject { + public string sort_criteria = "+dc:title"; + public int child_count = 10; + public bool create_mode_enabled = false; + public int all_child_count { + get { return this.child_count; } + } + public async MediaObjects? get_children ( + uint offset, + uint max_count, + string sort_criteria, + Cancellable? cancellable) + throws Error { + Idle.add ( () => { get_children.callback (); return false; }); + yield; + + var result = new MediaObjects (); + for (int i = 0; i < 10; ++i) { + result.add (new MediaObject ()); + } + + return result; + } + + internal void check_search_expression (SearchExpression? expression) {} +} + +public class TestContainer : MediaContainer, Rygel.SearchableContainer { + public MainLoop loop; + public Gee.ArrayList search_classes { get; set; default = new + Gee.ArrayList ();} + + public async void test_search_no_limit () { + uint total_matches = 0; + + // check corners + try { + var result = yield search (null, 0, 0, out total_matches, "", null); + assert (total_matches == 10); + assert (result.size == 10); + } catch (GLib.Error error) { + assert_not_reached (); + } + + try { + var result = yield search (null, 10, 0, out total_matches, "", null); + assert (total_matches == 10); + assert (result.size == 0); + } catch (GLib.Error error) { + assert_not_reached (); + } + + for (int i = 1; i < 10; ++i) { + try { + var result = yield search (null, i, 0, out total_matches, "", null); + assert (total_matches == 10); + assert (result.size == 10 - i); + } catch (GLib.Error error) { + assert_not_reached (); + } + } + + this.loop.quit (); + } + + public async void test_search_with_limit () { + uint total_matches; + + // check corners + try { + var result = yield search (null, 0, 4, out total_matches, "", null); + assert (total_matches == 0); + assert (result.size == 4); + } catch (GLib.Error error) { + assert_not_reached (); + } + + try + { + var result = yield search (null, 10, 4, out total_matches, "", null); + assert (total_matches == 0); + assert (result.size == 0); + } catch (GLib.Error error) { + assert_not_reached (); + } + + for (int i = 1; i < 10; ++i) { + try { + var result = yield search (null, i, 3, out total_matches, "", null); + assert (total_matches == 0); + assert (result.size == int.min (10 - i, 3)); + } catch (GLib.Error error) { + assert_not_reached (); + } + } + + this.loop.quit (); + } + + /* TODO: This is just here to avoid a warning about + * serialize_search_parameters() not being used. + * How should this really be tested? + */ + public void test_serialization() { + var writer = new GUPnP.DIDLLiteWriter(null); + var didl_container = writer.add_container(); + serialize_search_parameters(didl_container); + } + + public async MediaObjects? search (SearchExpression? expression, + uint offset, + uint max_count, + out uint total_matches, + string sort_criteria, + Cancellable? cancellable) + throws Error { + return yield this.simple_search (expression, + offset, + max_count, + out total_matches, + sort_criteria ?? this.sort_criteria, + cancellable); + } + +} + +public class MediaObjects : Gee.ArrayList { + public override Gee.List? slice (int start, int stop) { + var slice = base.slice (start, stop); + var ret = new MediaObjects (); + + ret.add_all (slice); + + return ret; + } +} + +int main () +{ + var c = new TestContainer (); + c.loop = new MainLoop (); + c.test_search_no_limit.begin (); + c.loop.run (); + c.test_search_with_limit.begin (); + c.loop.run (); + + return 0; +} -- cgit v1.2.1