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-hudappindicatorsource"
19
#include "hudsettings.h"
20
#include "hudsource.h"
22
#include "hudindicatorsource.h"
23
#include "hudtestutils.h"
25
#include <glib-object.h>
27
#include <libdbustest/dbus-test.h>
29
/* hardcode some parameters for reasons of determinism.
31
HudSettings hud_settings = {
32
.indicator_penalty = 50,
35
.end_drop_penalty = 1,
42
test_indicator_source_datetime ()
44
const gchar *dbus_name = "com.canonical.indicator.datetime";
45
const gchar *dbus_menu_path = "/com/canonical/indicator/datetime/menu";
46
// const gchar *indicator_name = "indicator-datetime";
48
DbusTestService *service = dbus_test_service_new (NULL);
50
hud_test_utils_json_loader_start_full (service, dbus_name, dbus_menu_path,
51
JSON_SOURCE_DATETIME);
52
GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
55
HudIndicatorSource* source = hud_indicator_source_new (connection);
56
hud_test_utils_process_mainloop (100);
58
g_assert(source != NULL);
59
g_assert(HUD_IS_INDICATOR_SOURCE(source));
61
HudTokenList *search = hud_token_list_new_from_string ("date time");
64
GPtrArray *results = g_ptr_array_new_with_free_func(g_object_unref);
65
hud_source_search(HUD_SOURCE(source), search, hud_test_utils_results_append_func, results);
66
g_assert_cmpuint(results->len, ==, 1);
67
hud_test_utils_source_assert_result (results, 0, "Date Time");
68
g_ptr_array_free(results, TRUE);
71
hud_token_list_free(search);
72
g_object_unref (source);
73
g_object_unref (service);
74
hud_test_utils_wait_for_connection_close(connection);
78
test_indicator_source_session ()
80
const gchar *dbus_name = "com.canonical.indicator.session";
81
const gchar *dbus_menu_path = "/com/canonical/indicator/session/menu";
82
// const gchar *indicator_name = "indicator-session-device";
84
DbusTestService *service = dbus_test_service_new (NULL);
86
hud_test_utils_json_loader_start_full (service, dbus_name, dbus_menu_path,
88
GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
91
HudIndicatorSource* source = hud_indicator_source_new (connection);
92
hud_test_utils_process_mainloop (100);
94
g_assert(source != NULL);
95
g_assert(HUD_IS_INDICATOR_SOURCE(source));
97
HudTokenList *search = hud_token_list_new_from_string ("session time");
100
GPtrArray *results = g_ptr_array_new_with_free_func(g_object_unref);
101
hud_source_search(HUD_SOURCE(source), search, hud_test_utils_results_append_func, results);
102
g_assert_cmpuint(results->len, ==, 1);
103
hud_test_utils_source_assert_result (results, 0, "Session Time");
104
g_ptr_array_free(results, TRUE);
107
hud_token_list_free(search);
108
g_object_unref (source);
109
g_object_unref (service);
110
hud_test_utils_wait_for_connection_close(connection);
114
test_indicator_source_sound ()
116
const gchar *dbus_name = "com.canonical.indicator.sound";
117
const gchar *dbus_menu_path = "/com/canonical/indicator/sound/menu";
118
// const gchar *indicator_name = "indicator-sound";
120
DbusTestService *service = dbus_test_service_new (NULL);
122
hud_test_utils_json_loader_start_full (service, dbus_name, dbus_menu_path,
124
GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
127
HudIndicatorSource* source = hud_indicator_source_new (connection);
128
hud_test_utils_process_mainloop (100);
130
g_assert(source != NULL);
131
g_assert(HUD_IS_INDICATOR_SOURCE(source));
133
HudTokenList *search = hud_token_list_new_from_string ("sound time");
136
GPtrArray *results = g_ptr_array_new_with_free_func(g_object_unref);
137
hud_source_search(HUD_SOURCE(source), search, hud_test_utils_results_append_func, results);
138
g_assert_cmpuint(results->len, ==, 1);
139
hud_test_utils_source_assert_result (results, 0, "Sound Time");
140
g_ptr_array_free(results, TRUE);
143
hud_token_list_free(search);
144
g_object_unref (source);
145
g_object_unref (service);
146
hud_test_utils_wait_for_connection_close(connection);
150
test_indicator_source_messages ()
152
const gchar *dbus_name = "com.canonical.indicator.messages";
153
const gchar *dbus_menu_path = "/com/canonical/indicator/messages/menu";
154
// const gchar *indicator_name = "indicator-messages";
156
DbusTestService *service = dbus_test_service_new (NULL);
158
hud_test_utils_start_menu_model_full(service, MODEL_SIMPLE, dbus_name, dbus_menu_path, FALSE);
159
GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
162
HudIndicatorSource* source = hud_indicator_source_new (connection);
163
hud_test_utils_process_mainloop (100);
165
g_assert(source != NULL);
166
g_assert(HUD_IS_INDICATOR_SOURCE(source));
168
HudTokenList *search = hud_token_list_new_from_string ("simple");
171
GPtrArray *results = g_ptr_array_new_with_free_func(g_object_unref);
172
hud_source_search(HUD_SOURCE(source), search, hud_test_utils_results_append_func, results);
173
g_assert_cmpuint(results->len, ==, 1);
174
hud_test_utils_source_assert_result (results, 0, "Simple");
175
g_ptr_array_free(results, TRUE);
178
hud_token_list_free(search);
179
g_object_unref (source);
180
g_object_unref (service);
181
hud_test_utils_wait_for_connection_close(connection);
185
main (int argc, char **argv)
187
#ifndef GLIB_VERSION_2_36
191
g_test_init (&argc, &argv, NULL);
192
g_test_add_func ("/hud/hudindicatorsource/datetime", test_indicator_source_datetime);
193
g_test_add_func ("/hud/hudindicatorsource/session", test_indicator_source_session);
194
g_test_add_func ("/hud/hudindicatorsource/sound", test_indicator_source_sound);
195
g_test_add_func ("/hud/hudindicatorsource/messages", test_indicator_source_messages);
197
return g_test_run ();