1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
* 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 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<string> search_classes { get; set; default = new
Gee.ArrayList<string> ();}
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<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 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;
}
|