~jbicha/hud/build-depend-on-valac-not-gir

« back to all changes in this revision

Viewing changes to tests/test-indicator-source.c

  • Committer: Tarmac
  • Author(s): Ted Gould, Pete Woods, Antti Kaijanmäki, Ted Gould, Albert Astals, Ryan Lortie, Łukasz 'sil2100' Zemczak, Albert Astals Cid, Mathieu Trudel-Lapierre, Kaleo, Tarmac, Ricardo Salveti de Araujo, Michael Terry, Automatic PS uploader
  • Date: 2013-04-10 16:04:51 UTC
  • mfrom: (227.3.148 phablet)
  • Revision ID: tarmac-20130410160451-o3owpv3zaxulm5of
HUD 2.0 Merge.

Approved by PS Jenkins bot, Mathieu Trudel-Lapierre.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
#define G_LOG_DOMAIN "test-hudappindicatorsource"
 
18
 
 
19
#include "hudsettings.h"
 
20
#include "hudsource.h"
 
21
#include "hudtoken.h"
 
22
#include "hudindicatorsource.h"
 
23
#include "hudtestutils.h"
 
24
 
 
25
#include <glib-object.h>
 
26
#include <gio/gio.h>
 
27
#include <libdbustest/dbus-test.h>
 
28
 
 
29
/* hardcode some parameters for reasons of determinism.
 
30
 */
 
31
HudSettings hud_settings = {
 
32
  .indicator_penalty = 50,
 
33
  .add_penalty = 10,
 
34
  .drop_penalty = 10,
 
35
  .end_drop_penalty = 1,
 
36
  .swap_penalty = 15,
 
37
  .max_distance = 30
 
38
};
 
39
 
 
40
 
 
41
static void
 
42
test_indicator_source_datetime ()
 
43
{
 
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";
 
47
 
 
48
  DbusTestService *service = dbus_test_service_new (NULL);
 
49
 
 
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,
 
53
      dbus_name, NULL);
 
54
 
 
55
  HudIndicatorSource* source = hud_indicator_source_new (connection);
 
56
  hud_test_utils_process_mainloop (100);
 
57
 
 
58
  g_assert(source != NULL);
 
59
  g_assert(HUD_IS_INDICATOR_SOURCE(source));
 
60
 
 
61
  HudTokenList *search = hud_token_list_new_from_string ("date time");
 
62
 
 
63
  {
 
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);
 
69
  }
 
70
 
 
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);
 
75
}
 
76
 
 
77
static void
 
78
test_indicator_source_session ()
 
79
{
 
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";
 
83
 
 
84
  DbusTestService *service = dbus_test_service_new (NULL);
 
85
 
 
86
  hud_test_utils_json_loader_start_full (service, dbus_name, dbus_menu_path,
 
87
      JSON_SOURCE_SESSION);
 
88
  GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
 
89
      dbus_name, NULL);
 
90
 
 
91
  HudIndicatorSource* source = hud_indicator_source_new (connection);
 
92
  hud_test_utils_process_mainloop (100);
 
93
 
 
94
  g_assert(source != NULL);
 
95
  g_assert(HUD_IS_INDICATOR_SOURCE(source));
 
96
 
 
97
  HudTokenList *search = hud_token_list_new_from_string ("session time");
 
98
 
 
99
  {
 
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);
 
105
  }
 
106
 
 
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);
 
111
}
 
112
 
 
113
static void
 
114
test_indicator_source_sound ()
 
115
{
 
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";
 
119
 
 
120
  DbusTestService *service = dbus_test_service_new (NULL);
 
121
 
 
122
  hud_test_utils_json_loader_start_full (service, dbus_name, dbus_menu_path,
 
123
      JSON_SOURCE_SOUND);
 
124
  GDBusConnection *connection = hud_test_utils_mock_dbus_connection_new (service,
 
125
      dbus_name, NULL);
 
126
 
 
127
  HudIndicatorSource* source = hud_indicator_source_new (connection);
 
128
  hud_test_utils_process_mainloop (100);
 
129
 
 
130
  g_assert(source != NULL);
 
131
  g_assert(HUD_IS_INDICATOR_SOURCE(source));
 
132
 
 
133
  HudTokenList *search = hud_token_list_new_from_string ("sound time");
 
134
 
 
135
  {
 
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);
 
141
  }
 
142
 
 
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);
 
147
}
 
148
 
 
149
static void
 
150
test_indicator_source_messages ()
 
151
{
 
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";
 
155
 
 
156
  DbusTestService *service = dbus_test_service_new (NULL);
 
157
 
 
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,
 
160
      dbus_name, NULL);
 
161
 
 
162
  HudIndicatorSource* source = hud_indicator_source_new (connection);
 
163
  hud_test_utils_process_mainloop (100);
 
164
 
 
165
  g_assert(source != NULL);
 
166
  g_assert(HUD_IS_INDICATOR_SOURCE(source));
 
167
 
 
168
  HudTokenList *search = hud_token_list_new_from_string ("simple");
 
169
 
 
170
  {
 
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);
 
176
  }
 
177
 
 
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);
 
182
}
 
183
 
 
184
int
 
185
main (int argc, char **argv)
 
186
{
 
187
#ifndef GLIB_VERSION_2_36
 
188
  g_type_init ();
 
189
#endif
 
190
 
 
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);
 
196
 
 
197
  return g_test_run ();
 
198
}