192
192
// ignore warnings
193
193
Test.log_set_fatal_handler (() => { return false; });
195
bool got_filters_update = false;
195
197
var proxy = acquire_test_proxy (HOME_SCOPE_DBUS_NAME, HOME_SCOPE_DBUS_PATH);
196
198
var channel_id = open_channel (proxy, ChannelType.GLOBAL, null);
198
200
assert (channel_id != null);
202
proxy.filter_settings_changed.connect ((chid, filter_rows) => {
203
got_filters_update = true;
200
206
var hints = new HashTable<string, Variant> (str_hash, str_equal);
201
207
hints["form-factor"] = "phone";
202
208
perform_search (proxy, channel_id, "metallica", hints, null);
210
assert (got_filters_update == false); // we expect no filter updates on the phone
205
213
internal void test_desktop_filters ()
207
215
// ignore warnings
208
216
Test.log_set_fatal_handler (() => { return false; });
218
int got_filters_update = 0;
210
220
var proxy = acquire_test_proxy (HOME_SCOPE_DBUS_NAME, HOME_SCOPE_DBUS_PATH);
211
221
var channel_id = open_channel (proxy, ChannelType.GLOBAL, null);
223
Variant? filters = null;
224
proxy.filter_settings_changed.connect ((chid, filter_rows) => {
225
got_filters_update += 1;
226
// note: there are 2 filter updates during search, but we care about the final value of filters
227
filters = filter_rows;
213
230
assert (channel_id != null);
231
assert (got_filters_update == 0);
233
// verify all filter options are initially inactive
234
int option_count = 0;
235
for (var iter = proxy.filters_model.get_first_iter (); iter != proxy.filters_model.get_last_iter (); iter = proxy.filters_model.next (iter))
237
var opts = proxy.filters_model.get_row (iter)[4].lookup_value ("options", null);
238
for (int i = 0; i<opts.n_children (); i++)
241
var opt = opts.get_child_value(i);
242
assert (opt.get_child_value (3).get_boolean () == false);
243
print ("%s ", opt.get_child_value (0).get_string());
247
assert (proxy.filters_model.get_n_rows () == 2);
248
assert (option_count == 17);
215
250
var hints = new HashTable<string, Variant> (str_hash, str_equal);
216
251
hints["form-factor"] = "desktop";
217
252
perform_search (proxy, channel_id, "iron maiden", hints, null);
219
hints.foreach ((k,v) => {
220
print ("%s: %s", k, v.print(true));
254
assert (got_filters_update == 2);
255
assert (filters.n_children() == 2); // two filters ('sources' and 'categories')
256
var src_filter = filters.get_child_value(0);
257
var cat_filter = filters.get_child_value(1);
259
// verify 'sources' filter
260
var opts = src_filter.get_child_value (4).lookup_value ("options", null);
261
var option_flags = new HashTable<string, bool>(str_hash, str_equal);
263
for (int i = 0; i<opts.n_children (); i++) // create scopeid -> enabled flag lookup for sources filter
265
var opt = opts.get_child_value(i);
266
option_flags[opt.get_child_value (0).get_string ()] = opt.get_child_value (3).get_boolean ();
269
assert (option_flags["reference-stackexchange.scope"] == false);
270
assert (option_flags["reference-dictionary.scope"] == false);
271
assert (option_flags["reference-themoviedb.scope"] == false);
272
assert (option_flags["masterscope_b-subscope1.scope"] == false);
273
assert (option_flags["masterscope_b-subscope2.scope"] == false);
274
assert (option_flags["masterscope_a-subscope1.scope"] == false);
275
assert (option_flags["masterscope_a-subscope2.scope"] == false);
276
assert (option_flags["more_suggestions-amazon.scope"] == false);
277
assert (option_flags["more_suggestions-etsy.scope"] == false);
278
assert (option_flags["more_suggestions-ebay.scope"] == false);
279
assert (option_flags["more_suggestions-skimlinks.scope"] == false);
281
assert (option_flags["more_suggestions-u1ms.scope"] == true);
282
assert (option_flags["reference-wikipedia.scope"] == true);
284
// verify 'categories' filter
285
opts = cat_filter.get_child_value (4).lookup_value ("options", null);
286
option_flags = new HashTable<string, bool>(str_hash, str_equal);
288
for (int i = 0; i<opts.n_children (); i++) // create scopeid -> enabled flag lookup for categories filter
290
var opt = opts.get_child_value(i);
291
option_flags[opt.get_child_value (0).get_string ()] = opt.get_child_value (3).get_boolean ();
294
assert (option_flags["masterscope_a.scope"] == false);
295
assert (option_flags["masterscope_b.scope"] == false);
297
assert (option_flags["more_suggestions.scope"] == true);
298
assert (option_flags["reference.scope"] == true);