2
* Copyright Ā© 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
#define G_LOG_DOMAIN "test-source"
19
#include "hudsettings.h"
22
#include "hudstringlist.h"
23
#include "hudsource.h"
24
#include "hudsourcelist.h"
25
#include "hudmanualsource.h"
26
#include "huddbusmenucollector.h"
27
#include "hud-query-iface.h"
28
#include "hudtestutils.h"
29
#include "app-list-dummy.h"
30
#include "query-columns.h"
32
#include <glib-object.h>
34
#include <libdbustest/dbus-test.h>
36
/* Define the global default timeout for hud_test_utils_process_mainloop */
37
#ifndef TEST_DEFAULT_TIMEOUT
38
#define TEST_DEFAULT_TIMEOUT 1000
41
/* hardcode some parameters for reasons of determinism.
43
HudSettings hud_settings = {
44
.indicator_penalty = 50,
47
.end_drop_penalty = 1,
54
GDBusConnection *session;
55
const gchar *object_path;
57
} TestSourceThreadData;
59
static HudQueryIfaceComCanonicalHudQuery*
60
test_source_create_proxy (TestSourceThreadData* thread_data)
63
GDBusConnection *session = G_DBUS_CONNECTION(thread_data->session);
64
const gchar* name = g_dbus_connection_get_unique_name (session);
66
HudQueryIfaceComCanonicalHudQuery *proxy =
67
hud_query_iface_com_canonical_hud_query_proxy_new_sync (session,
68
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, name, thread_data->object_path, NULL,
70
g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(proxy), 30 * 1000);
73
g_warning("%s %s\n", "The New Proxy request failed:", error->message);
79
g_debug("Created Proxy to the query: %s", thread_data->object_path);
82
/* Make sure we have a connection through the life
84
g_object_set_data_full(G_OBJECT(proxy), "test-source-bus-ensure", g_object_ref(session), g_object_unref);
90
test_source_call_close_query (gpointer user_data)
92
HudQueryIfaceComCanonicalHudQuery *proxy = test_source_create_proxy (
93
(TestSourceThreadData*) user_data);
96
if (!hud_query_iface_com_canonical_hud_query_call_close_query_sync (proxy,
99
g_warning("%s %s\n", "The Close Query request failed:", error->message);
100
g_error_free (error);
103
g_object_unref (proxy);
109
test_source_call_update_query (gpointer user_data)
111
TestSourceThreadData* thread_data = (TestSourceThreadData*) user_data;
112
HudQueryIfaceComCanonicalHudQuery *proxy = test_source_create_proxy (
116
GError *error = NULL;
117
if (!hud_query_iface_com_canonical_hud_query_call_update_query_sync (proxy,
118
thread_data->query, &model_revision, NULL, &error))
120
g_warning("%s %s\n", "The Update Query request failed:", error->message);
121
g_error_free (error);
124
g_object_unref (proxy);
130
test_source_call_update_app (gpointer user_data)
132
TestSourceThreadData* thread_data = (TestSourceThreadData*) user_data;
133
HudQueryIfaceComCanonicalHudQuery *proxy = test_source_create_proxy (
137
GError *error = NULL;
138
if (!hud_query_iface_com_canonical_hud_query_call_update_app_sync (proxy,
139
thread_data->query, &model_revision, NULL, &error))
141
g_warning("%s %s\n", "The Update App request failed:", error->message);
142
g_error_free (error);
145
g_object_unref (proxy);
151
test_source_make_assertions (HudQuery* query, const gchar *appstack,
152
const gchar *path, const gchar *name, const gchar **expected_rows,
153
const guint32 *expected_distances, const gint32 *expected_starts,
154
const gint32 *expected_stops, const guint expected_count)
158
g_assert_cmpstr(hud_query_get_appstack_name(query), ==, appstack);
159
g_assert_cmpstr(hud_query_get_path(query), ==, path);
160
g_assert_cmpstr(hud_query_get_results_name(query), ==, name);
162
DeeModel* model = hud_query_get_results_model (query);
163
g_assert_cmpint(dee_model_get_n_rows(model), ==, expected_count);
165
for (row = 0; row < expected_count; row++)
167
DeeModelIter* iter = dee_model_get_iter_at_row (model, row);
169
g_debug("Result: %s", dee_model_get_string(model, iter, HUD_QUERY_RESULTS_COMMAND_NAME));
170
g_debug("Expected: %s", expected_rows[row]);
171
g_debug("Distance: %d", dee_model_get_uint32(model, iter, HUD_QUERY_RESULTS_DISTANCE));
172
g_debug("Exp Distance: %d", expected_distances[row]);
174
GVariant * highlights = dee_model_get_value(model, iter, HUD_QUERY_RESULTS_COMMAND_HIGHLIGHTS);
175
g_assert(highlights != NULL);
177
g_debug("Highlight Count: %d", (guint)g_variant_n_children(highlights));
178
g_debug("Exp Highlight Cnt: %d", expected_starts[row] == -1 ? 0 : 1);
180
if (expected_starts[row] != -1)
182
g_debug("Highlights: %s", g_variant_print(highlights, FALSE));
183
g_debug("Exp Highlights: (%d, %d)", expected_starts[row], expected_stops[row]);
186
g_assert_cmpstr(dee_model_get_string(model, iter, HUD_QUERY_RESULTS_COMMAND_NAME), ==, expected_rows[row]);
187
g_assert_cmpint(dee_model_get_uint32(model, iter, HUD_QUERY_RESULTS_DISTANCE), ==, expected_distances[row]);
188
g_assert_cmpint(g_variant_n_children(highlights), ==, (expected_starts[row] == -1 ? 0 : 1));
190
if (expected_starts[row] != -1)
192
GVariant * highlight = g_variant_get_child_value(highlights, 0);
193
GVariant * vstart = g_variant_get_child_value(highlight, 0);
194
GVariant * vstop = g_variant_get_child_value(highlight, 1);
196
g_assert_cmpint(g_variant_get_int32(vstart), ==, expected_starts[row]);
197
g_assert_cmpint(g_variant_get_int32(vstop), ==, expected_stops[row]);
199
g_variant_unref(vstop);
200
g_variant_unref(vstart);
201
g_variant_unref(highlight);
204
g_variant_unref(highlights);
209
test_source_make_assertions_ext (HudQuery* query, const gchar *appstack,
210
const gchar **expected_appstack_ids, const gchar **expected_appstack_icons, const guint expected_appstack_count,
211
const gchar *path, const gchar *name, const gchar **expected_rows,
212
const guint32 *expected_distances, const gint32 *expected_starts,
213
const gint32 *expected_stops, const guint expected_count)
217
test_source_make_assertions(query, appstack, path, name, expected_rows, expected_distances, expected_starts, expected_stops, expected_count);
219
DeeModel* model = hud_query_get_appstack_model (query);
220
g_assert_cmpint(dee_model_get_n_rows(model), ==, expected_appstack_count);
222
for (row = 0; row < expected_appstack_count; row++)
224
DeeModelIter* iter = dee_model_get_iter_at_row (model, row);
226
g_debug("Id: %s", dee_model_get_string(model, iter, HUD_QUERY_APPSTACK_APPLICATION_ID));
227
g_debug("Expected Id: %s", expected_appstack_ids[row]);
228
g_debug("Icon: %s", dee_model_get_string(model, iter, HUD_QUERY_APPSTACK_ICON_NAME));
229
g_debug("Exp Icon: %s", expected_appstack_icons[row]);
231
g_assert_cmpstr(dee_model_get_string(model, iter, HUD_QUERY_APPSTACK_APPLICATION_ID), ==, expected_appstack_ids[row]);
232
g_assert_cmpstr(dee_model_get_string(model, iter, HUD_QUERY_APPSTACK_ICON_NAME), ==, expected_appstack_icons[row]);
237
test_source_create_query (GDBusConnection *session, HudSource *source, HudApplicationList * list, const gchar *search, const guint query_count)
239
g_debug ("query: [%s], on [%s]", search, g_dbus_connection_get_unique_name(session));
241
HudQuery * query = hud_query_new (source, NULL, list, search, 1u << 30, session, NULL, query_count);
247
test_hud_query_sequence ()
249
DbusTestService * service = NULL;
250
GDBusConnection * session = NULL;
252
hud_test_utils_start_dbusmenu_mock_app (&service, &session, JSON_SOURCE);
254
HudDbusmenuCollector *collector = hud_dbusmenu_collector_new_for_endpoint (
255
"test-id", "Prefix", "no-icon", 0, /* penalty */
256
HUD_TEST_UTILS_LOADER_NAME, HUD_TEST_UTILS_LOADER_PATH,
257
HUD_SOURCE_ITEM_TYPE_BACKGROUND_APP);
258
g_assert(collector != NULL);
259
g_assert(HUD_IS_DBUSMENU_COLLECTOR(collector));
261
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
263
HudManualSource *manual_source = hud_manual_source_new("manual_app", "manual_icon");
265
HudApplicationList * applist = HUD_APPLICATION_LIST(app_list_dummy_new(HUD_SOURCE(collector)));
267
HudSourceList *source_list = hud_source_list_new();
268
hud_source_list_add(source_list, HUD_SOURCE(collector));
269
hud_source_list_add(source_list, HUD_SOURCE(manual_source));
271
hud_source_use(HUD_SOURCE(source_list));
274
gchar *search = "ash";
275
const gchar *expected[5] = { "any rash", "stray slash", "swift sad", "itch step", "mess strand" };
276
const guint32 expected_distances[5] = { 10, 20, 22, 23, 25 };
277
const gint32 expected_starts[5] = { 5, 8, -1, -1, -1 };
278
const gint32 expected_stops[5] = { 8, 11, -1, -1, -1 };
279
const gchar *appstack = "com.canonical.hud.query0.appstack";
280
const gchar *path = "/com/canonical/hud/query0";
281
const gchar *name = "com.canonical.hud.query0.results";
283
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 0);
284
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
285
g_object_unref (query);
289
gchar *search = "mess";
290
const gchar *expected[1] = { "mess strand"};
291
const guint32 expected_distances[1] = { 1 };
292
const gint32 expected_starts[1] = { 0 };
293
const gint32 expected_stops[1] = { 4 };
294
const gchar *appstack = "com.canonical.hud.query1.appstack";
295
const gchar *path = "/com/canonical/hud/query1";
296
const gchar *name = "com.canonical.hud.query1.results";
298
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 1);
299
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
300
g_object_unref (query);
304
gchar *search = "dare";
305
const gchar *expected[2] = { "mess strand", "bowl"};
306
const guint32 expected_distances[2] = { 2, 30 };
307
const gint32 expected_starts[2] = { -1, -1 };
308
const gint32 expected_stops[2] = { -1, -1 };
309
const gchar *appstack = "com.canonical.hud.query2.appstack";
310
const gchar *path = "/com/canonical/hud/query2";
311
const gchar *name = "com.canonical.hud.query2.results";
313
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 2);
314
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
315
g_object_unref (query);
318
/* This time closing using dbus call */
320
gchar *search = "itch step";
321
const gchar *expected[1] = { "itch step"};
322
const guint32 expected_distances[1] = { 0 };
323
const gint32 expected_starts[1] = { 0 };
324
const gint32 expected_stops[1] = { 9 };
325
const gchar *appstack = "com.canonical.hud.query3.appstack";
326
const gchar *path = "/com/canonical/hud/query3";
327
const gchar *name = "com.canonical.hud.query3.results";
329
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 3);
330
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
332
TestSourceThreadData thread_data = {session, path};
333
GThread* thread = g_thread_new ("close_query", test_source_call_close_query, &thread_data);
334
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
335
g_thread_join(thread);
338
/* This time updating query using dbus call */
340
gchar *search = "ash";
341
const gchar *expected[5] = { "any rash", "stray slash", "swift sad", "itch step", "mess strand" };
342
const guint32 expected_distances[5] = { 10, 20, 22, 23, 25 };
343
const gint32 expected_starts[5] = { 5, 8, -1, -1, -1 };
344
const gint32 expected_stops[5] = { 8, 11, -1, -1, -1 };
345
const gchar *appstack = "com.canonical.hud.query4.appstack";
346
const gchar *path = "/com/canonical/hud/query4";
347
const gchar *name = "com.canonical.hud.query4.results";
349
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 4);
350
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
352
TestSourceThreadData thread_data = {session, path, "dare"};
353
GThread* thread = g_thread_new ("update_query", test_source_call_update_query, &thread_data);
354
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
355
g_thread_join(thread);
357
const gchar *expected_after[2] = { "mess strand", "bowl"};
358
const guint32 expected_distances_after[2] = { 2, 30 };
359
const gint32 expected_starts_after[2] = { -1, -1 };
360
const gint32 expected_stops_after[2] = { -1, -1 };
362
test_source_make_assertions (query, appstack, path, name, expected_after, expected_distances_after, expected_starts_after, expected_stops_after, G_N_ELEMENTS(expected_after));
364
g_object_unref (query);
367
/* Adding new data to the manual source */
369
gchar *search = "dare";
370
const gchar *expected[2] = { "mess strand", "bowl"};
371
const guint32 expected_distances[2] = { 2, 30 };
372
const gint32 expected_starts[2] = { -1, -1 };
373
const gint32 expected_stops[2] = { -1, -1 };
374
const gchar *appstack = "com.canonical.hud.query5.appstack";
375
const gchar *path = "/com/canonical/hud/query5";
376
const gchar *name = "com.canonical.hud.query5.results";
378
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 5);
379
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
381
HudStringList *tokens = hud_string_list_add_item("extra", NULL);
382
tokens = hud_string_list_add_item("something dare", tokens);
383
hud_manual_source_add(manual_source, tokens, NULL, "shortcut1", TRUE);
385
HudStringList *tokens2 = hud_string_list_add_item("extra", NULL);
386
tokens2 = hud_string_list_add_item("something else darn", tokens2);
387
hud_manual_source_add(manual_source, tokens2, NULL, "shortcut2", TRUE);
389
app_list_dummy_set_focus(APP_LIST_DUMMY(applist), HUD_SOURCE(manual_source));
391
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT / 2);
393
const gchar *expected_after[2] = { "something dare", "something else darn"};
394
const guint32 expected_distances_after[2] = { 0, 11 };
395
const gint32 expected_starts_after[2] = { 10, -1 };
396
const gint32 expected_stops_after[2] = { 14, -1 };
398
g_assert(G_N_ELEMENTS(expected_after) == G_N_ELEMENTS(expected_distances_after));
399
test_source_make_assertions (query, appstack, path, name, expected_after, expected_distances_after, expected_starts_after, expected_stops_after, G_N_ELEMENTS(expected_after));
401
g_object_unref (query);
404
/* Test query currentSource */
406
gchar *search = "dare";
407
const gchar *expected[2] = { "mess strand", "bowl"};
408
const guint32 expected_distances[2] = { 2, 30 };
409
const gint32 expected_starts[2] = { -1, -1 };
410
const gint32 expected_stops[2] = { -1, -1 };
411
const gchar *appstack_expected_ids[2] = { "manual_app", "test-id"};
412
const gchar *appstack_expected_icons[2] = { "manual_icon", "no-icon"};
413
const gchar *appstack = "com.canonical.hud.query6.appstack";
414
const gchar *path = "/com/canonical/hud/query6";
415
const gchar *name = "com.canonical.hud.query6.results";
417
g_assert(G_N_ELEMENTS(appstack_expected_ids) == G_N_ELEMENTS(appstack_expected_icons));
418
g_assert(G_N_ELEMENTS(expected) == G_N_ELEMENTS(expected_distances));
420
AppListDummy * dummy = app_list_dummy_new(HUD_SOURCE(collector));
421
HudQuery *query = hud_query_new (HUD_SOURCE(source_list), NULL, HUD_APPLICATION_LIST(dummy), search, 1u << 30, session, NULL, 6);
422
test_source_make_assertions_ext (query, appstack, appstack_expected_ids, appstack_expected_icons, G_N_ELEMENTS(appstack_expected_ids), path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
424
// Change the app to the manual_source
425
g_debug("Changing to 'manual_app'");
426
TestSourceThreadData thread_data = {session, path, "manual_app"};
427
GThread* thread = g_thread_new ("update_app", test_source_call_update_app, &thread_data);
428
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
429
g_thread_join(thread);
431
const gchar *expected_after[2] = { "something dare", "something else darn"};
432
const guint32 expected_distances_after[2] = { 0, 11 };
433
const gint32 expected_starts_after[2] = { 10, -1 };
434
const gint32 expected_stops_after[2] = { 14, -1 };
435
test_source_make_assertions_ext (query, appstack, appstack_expected_ids, appstack_expected_icons, G_N_ELEMENTS(appstack_expected_ids), path, name, expected_after, expected_distances_after, expected_starts_after, expected_stops_after, G_N_ELEMENTS(expected_after));
437
g_object_unref (query);
438
g_object_unref(dummy);
441
hud_source_unuse (HUD_SOURCE(source_list) );
443
g_object_unref (source_list);
444
g_object_unref (collector);
445
g_object_unref (manual_source);
446
g_object_unref (applist);
448
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
450
g_object_unref (service);
451
hud_test_utils_wait_for_connection_close(session);
455
test_hud_query_sequence_counter_increment ()
457
DbusTestService * service = NULL;
458
GDBusConnection * session = NULL;
460
hud_test_utils_start_dbusmenu_mock_app (&service, &session, JSON_SOURCE);
462
HudDbusmenuCollector *collector = hud_dbusmenu_collector_new_for_endpoint (
463
"test-id", "Prefix", "no-icon", 0, /* penalty */
464
HUD_TEST_UTILS_LOADER_NAME, HUD_TEST_UTILS_LOADER_PATH,
465
HUD_SOURCE_ITEM_TYPE_BACKGROUND_APP);
466
g_assert(collector != NULL);
467
g_assert(HUD_IS_DBUSMENU_COLLECTOR(collector));
469
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
471
HudManualSource *manual_source = hud_manual_source_new("manual-id", "manual-icon");
473
HudApplicationList * applist = HUD_APPLICATION_LIST(app_list_dummy_new(HUD_SOURCE(collector)));
475
HudSourceList *source_list = hud_source_list_new();
476
hud_source_list_add(source_list, HUD_SOURCE(collector));
477
hud_source_list_add(source_list, HUD_SOURCE(manual_source));
479
hud_source_use(HUD_SOURCE(source_list));
482
gchar *search = "ash";
483
const gchar *expected[5] = { "any rash", "stray slash", "swift sad", "itch step", "mess strand" };
484
const guint32 expected_distances[5] = { 10, 20, 22, 23, 25 };
485
const gint32 expected_starts[5] = { 5, 8, -1, -1, -1 };
486
const gint32 expected_stops[5] = { 8, 11, -1, -1, -1 };
487
const gchar *appstack = "com.canonical.hud.query6.appstack";
488
const gchar *path = "/com/canonical/hud/query6";
489
const gchar *name = "com.canonical.hud.query6.results";
491
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 6);
492
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
493
g_object_unref (query);
497
gchar *search = "mess";
498
const gchar *expected[1] = { "mess strand"};
499
const guint32 expected_distances[1] = { 1 };
500
const gint32 expected_starts[1] = { 0 };
501
const gint32 expected_stops[1] = { 4 };
502
const gchar *appstack = "com.canonical.hud.query7.appstack";
503
const gchar *path = "/com/canonical/hud/query7";
504
const gchar *name = "com.canonical.hud.query7.results";
506
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 7);
507
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
508
g_object_unref (query);
512
gchar *search = "dare";
513
const gchar *expected[2] = { "mess strand", "bowl"};
514
const guint32 expected_distances[2] = { 2, 30 };
515
const gint32 expected_starts[2] = { -1, -1 };
516
const gint32 expected_stops[2] = { -1, -1 };
517
const gchar *appstack = "com.canonical.hud.query8.appstack";
518
const gchar *path = "/com/canonical/hud/query8";
519
const gchar *name = "com.canonical.hud.query8.results";
521
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 8);
522
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
523
g_object_unref (query);
526
/* This time closing using dbus call */
528
gchar *search = "itch step";
529
const gchar *expected[1] = { "itch step"};
530
const guint32 expected_distances[1] = { 0 };
531
const gint32 expected_starts[1] = { 0 };
532
const gint32 expected_stops[1] = { 9 };
533
const gchar *appstack = "com.canonical.hud.query9.appstack";
534
const gchar *path = "/com/canonical/hud/query9";
535
const gchar *name = "com.canonical.hud.query9.results";
537
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 9);
538
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
540
TestSourceThreadData thread_data = {session, path};
541
GThread* thread = g_thread_new ("close_query", test_source_call_close_query, &thread_data);
542
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
543
g_thread_join(thread);
546
/* This time updating query using dbus call */
548
gchar *search = "ash";
549
const gchar *expected[5] = { "any rash", "stray slash", "swift sad", "itch step", "mess strand" };
550
const guint32 expected_distances[5] = { 10, 20, 22, 23, 25 };
551
const gint32 expected_starts[5] = { 5, 8, -1, -1, -1 };
552
const gint32 expected_stops[5] = { 8, 11, -1, -1, -1 };
553
const gchar *appstack = "com.canonical.hud.query10.appstack";
554
const gchar *path = "/com/canonical/hud/query10";
555
const gchar *name = "com.canonical.hud.query10.results";
557
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 10);
558
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
560
TestSourceThreadData thread_data = {session, path, "dare"};
561
GThread* thread = g_thread_new ("update_query", test_source_call_update_query, &thread_data);
562
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
563
g_thread_join(thread);
565
const gchar *expected_after[2] = { "mess strand", "bowl"};
566
const guint32 expected_distances_after[2] = { 2, 30 };
567
const gint32 expected_starts_after[2] = { -1, -1 };
568
const gint32 expected_stops_after[2] = { -1, -1 };
570
test_source_make_assertions (query, appstack, path, name, expected_after, expected_distances_after, expected_starts_after, expected_stops_after, G_N_ELEMENTS(expected_after));
572
g_object_unref (query);
575
/* Adding new data to the manual source */
577
gchar *search = "dare";
578
const gchar *expected[2] = { "mess strand", "bowl"};
579
const guint32 expected_distances[2] = { 2, 30 };
580
const gint32 expected_starts[2] = { -1, -1 };
581
const gint32 expected_stops[2] = { -1, -1 };
582
const gchar *appstack = "com.canonical.hud.query11.appstack";
583
const gchar *path = "/com/canonical/hud/query11";
584
const gchar *name = "com.canonical.hud.query11.results";
586
HudQuery *query = test_source_create_query (session, HUD_SOURCE(source_list), applist, search, 11);
587
test_source_make_assertions (query, appstack, path, name, expected, expected_distances, expected_starts, expected_stops, G_N_ELEMENTS(expected));
589
HudStringList *tokens = hud_string_list_add_item("extra", NULL);
590
tokens = hud_string_list_add_item("something dare", tokens);
591
hud_manual_source_add(manual_source, tokens, NULL, "shortcut1", TRUE);
593
HudStringList *tokens2 = hud_string_list_add_item("extra", NULL);
594
tokens2 = hud_string_list_add_item("something else darn", tokens2);
595
hud_manual_source_add(manual_source, tokens2, NULL, "shortcut2", TRUE);
597
app_list_dummy_set_focus(APP_LIST_DUMMY(applist), HUD_SOURCE(manual_source));
599
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT / 2);
601
const gchar *expected_after[2] = { "something dare", "something else darn" };
602
const guint32 expected_distances_after[2] = { 0, 11 };
603
const gint32 expected_starts_after[2] = { 10, -1 };
604
const gint32 expected_stops_after[2] = { 14, -1 };
606
g_assert(G_N_ELEMENTS(expected_after) == G_N_ELEMENTS(expected_distances_after));
607
test_source_make_assertions (query, appstack, path, name, expected_after, expected_distances_after, expected_starts_after, expected_stops_after, G_N_ELEMENTS(expected_after));
609
g_object_unref (query);
612
hud_source_unuse (HUD_SOURCE(source_list) );
614
g_object_unref (source_list);
615
g_object_unref (collector);
616
g_object_unref (manual_source);
617
g_object_unref (applist);
619
hud_test_utils_process_mainloop (TEST_DEFAULT_TIMEOUT);
621
g_object_unref (service);
622
hud_test_utils_wait_for_connection_close(session);
626
main (int argc, char **argv)
628
#ifndef GLIB_VERSION_2_36
632
g_test_init (&argc, &argv, NULL);
633
g_test_add_func ("/hud/source/query_sequence", test_hud_query_sequence);
634
g_test_add_func ("/hud/source/query_sequence_counter_increment", test_hud_query_sequence_counter_increment);
636
return g_test_run ();