2 * Copyright (C) 2012 Jens Georg.
4 * Author: Jens Georg <mail@jensge.org>
6 * This file is part of Rygel.
8 * Rygel is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Rygel is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 public class RelationalExpression : SearchExpression {
26 namespace SearchCriteriaOp {
27 public const string EQ = "=";
30 public class SearchExpression : Object {
31 public string operand1;
32 public string operand2;
35 public bool satisfied_by (MediaObject object) {
40 public class MediaObject : Object {
43 public class MediaContainer : MediaObject {
44 public string sort_criteria = "+dc:title";
45 public int child_count = 10;
46 public bool create_mode_enabled = false;
47 public int all_child_count {
48 get { return this.child_count; }
50 public async MediaObjects? get_children (
54 Cancellable? cancellable)
56 Idle.add ( () => { get_children.callback (); return false; });
59 var result = new MediaObjects ();
60 for (int i = 0; i < 10; ++i) {
61 result.add (new MediaObject ());
67 internal void check_search_expression (SearchExpression? expression) {}
70 public class TestContainer : MediaContainer, Rygel.SearchableContainer {
72 public Gee.ArrayList<string> search_classes { get; set; default = new
73 Gee.ArrayList<string> ();}
75 public async void test_search_no_limit () {
76 uint total_matches = 0;
80 var result = yield search (null, 0, 0, out total_matches, "", null);
81 assert (total_matches == 10);
82 assert (result.size == 10);
83 } catch (GLib.Error error) {
84 assert_not_reached ();
88 var result = yield search (null, 10, 0, out total_matches, "", null);
89 assert (total_matches == 10);
90 assert (result.size == 0);
91 } catch (GLib.Error error) {
92 assert_not_reached ();
95 for (int i = 1; i < 10; ++i) {
97 var result = yield search (null, i, 0, out total_matches, "", null);
98 assert (total_matches == 10);
99 assert (result.size == 10 - i);
100 } catch (GLib.Error error) {
101 assert_not_reached ();
108 public async void test_search_with_limit () {
113 var result = yield search (null, 0, 4, out total_matches, "", null);
114 assert (total_matches == 0);
115 assert (result.size == 4);
116 } catch (GLib.Error error) {
117 assert_not_reached ();
122 var result = yield search (null, 10, 4, out total_matches, "", null);
123 assert (total_matches == 0);
124 assert (result.size == 0);
125 } catch (GLib.Error error) {
126 assert_not_reached ();
129 for (int i = 1; i < 10; ++i) {
131 var result = yield search (null, i, 3, out total_matches, "", null);
132 assert (total_matches == 0);
133 assert (result.size == int.min (10 - i, 3));
134 } catch (GLib.Error error) {
135 assert_not_reached ();
142 /* TODO: This is just here to avoid a warning about
143 * serialize_search_parameters() not being used.
144 * How should this really be tested?
146 public void test_serialization() {
147 var writer = new GUPnP.DIDLLiteWriter(null);
148 var didl_container = writer.add_container();
149 serialize_search_parameters(didl_container);
152 public async MediaObjects? search (SearchExpression? expression,
155 out uint total_matches,
156 string sort_criteria,
157 Cancellable? cancellable)
159 return yield this.simple_search (expression,
163 sort_criteria ?? this.sort_criteria,
169 public class MediaObjects : Gee.ArrayList<MediaObject> {
170 public override Gee.List<MediaObject>? slice (int start, int stop) {
171 var slice = base.slice (start, stop);
172 var ret = new MediaObjects ();
182 var c = new TestContainer ();
183 c.loop = new MainLoop ();
184 c.test_search_no_limit.begin ();
186 c.test_search_with_limit.begin ();