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 uint child_count = 10;
45 public async MediaObjects? get_children (
49 Cancellable? cancellable)
51 Idle.add ( () => { get_children.callback (); return false; });
54 var result = new MediaObjects ();
55 for (int i = 0; i < 10; ++i) {
56 result.add (new MediaObject ());
63 public class TestContainer : MediaContainer, Rygel.SearchableContainer {
65 public Gee.ArrayList<string> search_classes { get; set; default = new
66 Gee.ArrayList<string> ();}
68 public async void test_search_no_limit () {
72 var result = yield search (null, 0, 0, out total_matches, "", null);
73 assert (total_matches == 10);
74 assert (result.size == 10);
76 result = yield search (null, 10, 0, out total_matches, "", null);
77 assert (total_matches == 10);
78 assert (result.size == 0);
80 for (int i = 1; i < 10; ++i) {
81 result = yield search (null, i, 0, out total_matches, "", null);
82 assert (total_matches == 10);
83 assert (result.size == 10 - i);
89 public async void test_search_with_limit () {
93 var result = yield search (null, 0, 4, out total_matches, "", null);
94 assert (total_matches == 0);
95 assert (result.size == 4);
97 result = yield search (null, 10, 4, out total_matches, "", null);
98 assert (total_matches == 0);
99 assert (result.size == 0);
101 for (int i = 1; i < 10; ++i) {
102 result = yield search (null, i, 3, out total_matches, "", null);
103 assert (total_matches == 0);
104 assert (result.size == int.min (10 - i, 3));
111 public async MediaObjects? search (SearchExpression? expression,
114 out uint total_matches,
115 string sort_criteria,
116 Cancellable? cancellable)
118 return yield this.simple_search (expression,
128 public class MediaObjects : Gee.ArrayList<MediaObject> {
129 public override Gee.List<MediaObject>? slice (int start, int stop) {
130 var slice = base.slice (start, stop);
131 var ret = new MediaObjects ();
141 var loop = new MainLoop ();
142 var c = new TestContainer ();
143 c.loop = new MainLoop ();
144 c.test_search_no_limit.begin ();
146 c.test_search_with_limit.begin ();