[rygel] tests: Add test for simple_search
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] tests: Add test for simple_search
- Date: Sun, 29 Jan 2012 11:33:33 +0000 (UTC)
commit 8cbc98368c0133bf9d0a6b63f6d9f6108c6f03dc
Author: Jens Georg <mail jensge org>
Date: Sun Jan 29 00:55:06 2012 +0100
tests: Add test for simple_search
https://bugzilla.gnome.org/show_bug.cgi?id=653120
tests/Makefile.am | 8 ++-
tests/rygel-searchable-container-test.vala | 146 ++++++++++++++++++++++++++++
tests/rygel-searchable-container.vala | 1 +
3 files changed, 154 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd26040..a05d0be 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -36,7 +36,8 @@ check_PROGRAMS = rygel-http-item-uri-test \
rygel-http-time-seek-test \
rygel-http-get-test \
rygel-album-art-spec-test \
- rygel-http-post-test
+ rygel-http-post-test \
+ rygel-searchable-container-test
TESTS = $(check_PROGRAMS)
@@ -77,6 +78,11 @@ rygel_album_art_spec_test_SOURCES = rygel-album-art-spec-test.vala \
../src/rygel/rygel-thumbnail.vala \
../src/rygel/rygel-icon-info.vala
+rygel_searchable_container_test_SOURCES = \
+ rygel-searchable-container.vala \
+ rygel-searchable-container-test.vala
+
+
if ALWAYS_TEST
all-local: check
endif
diff --git a/tests/rygel-searchable-container-test.vala b/tests/rygel-searchable-container-test.vala
new file mode 100644
index 0000000..f7024fb
--- /dev/null
+++ b/tests/rygel-searchable-container-test.vala
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2012 Jens Georg.
+ *
+ * Author: Jens Georg <mail jensge 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.
+ */
+
+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 uint child_count = 10;
+ public async MediaObjects? get_children (uint offset,
+ uint max_count,
+ 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;
+ }
+}
+
+public class TestContainer : MediaContainer, Rygel.SearchableContainer {
+ public MainLoop loop;
+ public Gee.ArrayList<string> search_classes { get; set; default = new
+ Gee.ArrayList<string> ();}
+
+ public async void test_search_no_limit () {
+ uint total_matches;
+
+ // check corners
+ var result = yield search (null, 0, 0, out total_matches, null);
+ assert (total_matches == 10);
+ assert (result.size == 10);
+
+ result = yield search (null, 10, 0, out total_matches, null);
+ assert (total_matches == 10);
+ assert (result.size == 0);
+
+ for (int i = 1; i < 10; ++i) {
+ result = yield search (null, i, 0, out total_matches, null);
+ assert (total_matches == 10);
+ assert (result.size == 10 - i);
+ }
+
+ this.loop.quit ();
+ }
+
+ public async void test_search_with_limit () {
+ uint total_matches;
+
+ // check corners
+ var result = yield search (null, 0, 4, out total_matches, null);
+ assert (total_matches == 0);
+ assert (result.size == 4);
+
+ result = yield search (null, 10, 4, out total_matches, null);
+ assert (total_matches == 0);
+ assert (result.size == 0);
+
+ for (int i = 1; i < 10; ++i) {
+ result = yield search (null, i, 3, out total_matches, null);
+ assert (total_matches == 0);
+ assert (result.size == int.min (10 - i, 3));
+ }
+
+ this.loop.quit ();
+ }
+
+
+ public async MediaObjects? search (SearchExpression? expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws Error {
+ return yield this.simple_search (expression,
+ offset,
+ max_count,
+ out total_matches,
+ cancellable);
+ }
+
+}
+
+public class MediaObjects : Gee.ArrayList<MediaObject> {
+ public override Gee.List<MediaObject>? slice (int start, int stop) {
+ var slice = base.slice (start, stop);
+ var ret = new MediaObjects ();
+
+ ret.add_all (slice);
+
+ return ret;
+ }
+}
+
+int main ()
+{
+ var loop = new MainLoop ();
+ 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/rygel-searchable-container.vala b/tests/rygel-searchable-container.vala
new file mode 120000
index 0000000..d9e0660
--- /dev/null
+++ b/tests/rygel-searchable-container.vala
@@ -0,0 +1 @@
+../src/rygel/rygel-searchable-container.vala
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]