58
58
IndicatorObjectClass parent_class;
61
GType test_object_get_type (void) G_GNUC_CONST;
63
IndicatorObject * test_object_new ();
65
IndicatorObjectEntry * test_object_add_entry (TestObject *self,
67
const gchar *icon_name);
61
GType test_object_get_type(void) G_GNUC_CONST;
63
IndicatorObject* test_object_new();
65
IndicatorObjectEntry* test_object_add_entry(TestObject* self,
67
const gchar* icon_name);
71
G_DEFINE_TYPE (TestObject, test_object, INDICATOR_OBJECT_TYPE);
71
G_DEFINE_TYPE(TestObject, test_object, INDICATOR_OBJECT_TYPE);
74
test_object_dispose (GObject *object)
74
test_object_dispose(GObject* object)
76
TestObject *self = TEST_OBJECT (object);
76
TestObject* self = TEST_OBJECT(object);
79
79
for (e = self->entries; e; e = e->next)
81
g_slice_free (IndicatorObjectEntry, e->data);
83
g_list_free (self->entries);
81
g_slice_free(IndicatorObjectEntry, e->data);
83
g_list_free(self->entries);
84
84
self->entries = NULL;
86
G_OBJECT_CLASS (test_object_parent_class)->dispose (object);
86
G_OBJECT_CLASS(test_object_parent_class)->dispose(object);
90
test_object_get_entries (IndicatorObject *io)
90
test_object_get_entries(IndicatorObject* io)
92
g_return_val_if_fail (TEST_IS_OBJECT (io), NULL);
92
g_return_val_if_fail(TEST_IS_OBJECT(io), NULL);
94
return g_list_copy (TEST_OBJECT (io)->entries);
94
return g_list_copy(TEST_OBJECT(io)->entries);
98
test_object_get_location (IndicatorObject *io,
99
IndicatorObjectEntry *entry)
101
g_return_val_if_fail (TEST_IS_OBJECT (io), 0);
103
return g_list_index (TEST_OBJECT (io)->entries, entry);
107
test_object_entry_activate (IndicatorObject *io,
108
IndicatorObjectEntry *entry,
115
test_object_class_init (TestObjectClass *klass)
117
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
118
IndicatorObjectClass *ind_class = INDICATOR_OBJECT_CLASS (klass);
98
test_object_get_location(IndicatorObject* io,
99
IndicatorObjectEntry* entry)
101
g_return_val_if_fail(TEST_IS_OBJECT(io), 0);
103
return g_list_index(TEST_OBJECT(io)->entries, entry);
107
test_object_entry_activate(IndicatorObject* io,
108
IndicatorObjectEntry* entry,
115
test_object_class_init(TestObjectClass* klass)
117
GObjectClass* obj_class = G_OBJECT_CLASS(klass);
118
IndicatorObjectClass* ind_class = INDICATOR_OBJECT_CLASS(klass);
120
120
obj_class->dispose = test_object_dispose;
128
test_object_init (TestObject *self)
136
return (IndicatorObject *)g_object_new (TEST_TYPE_OBJECT, NULL);
139
IndicatorObjectEntry *
140
test_object_add_entry (TestObject *self,
142
const gchar *icon_name)
144
IndicatorObjectEntry *entry;
145
g_return_val_if_fail (TEST_IS_OBJECT (self), NULL);
147
entry = g_slice_new0 (IndicatorObjectEntry);
148
entry->label = (GtkLabel *)gtk_label_new (label);
149
entry->image = icon_name ? (GtkImage *)gtk_image_new_from_icon_name (icon_name,
150
GTK_ICON_SIZE_MENU) : NULL;
128
test_object_init(TestObject* self)
136
return (IndicatorObject*)g_object_new(TEST_TYPE_OBJECT, NULL);
139
IndicatorObjectEntry*
140
test_object_add_entry(TestObject* self,
142
const gchar* icon_name)
144
IndicatorObjectEntry* entry;
145
g_return_val_if_fail(TEST_IS_OBJECT(self), NULL);
147
entry = g_slice_new0(IndicatorObjectEntry);
148
entry->label = (GtkLabel*)gtk_label_new(label);
149
entry->image = icon_name ? (GtkImage*)gtk_image_new_from_icon_name(icon_name,
150
GTK_ICON_SIZE_MENU) : NULL;
151
151
entry->menu = NULL;
153
self->entries = g_list_append (self->entries, entry);
153
self->entries = g_list_append(self->entries, entry);
155
g_signal_emit (self, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, entry, TRUE);
155
g_signal_emit(self, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED_ID, 0, entry, TRUE);
161
test_object_show_entry (TestObject *self,
162
IndicatorObjectEntry *entry,
161
test_object_show_entry(TestObject* self,
162
IndicatorObjectEntry* entry,
165
g_signal_emit (self, INDICATOR_OBJECT_SIGNAL_MENU_SHOW_ID, 0, entry, timestamp);
165
g_signal_emit(self, INDICATOR_OBJECT_SIGNAL_MENU_SHOW_ID, 0, entry, timestamp);
168
168
//----------------------- /TESTING INDICATOR STUFF ----------------------------
170
170
//------------------------ USEFUL FUNCTIONS -----------------------------------
173
get_n_indicators_in_result (GVariant *result)
173
get_n_indicators_in_result(GVariant* result)
176
gchar *current_object_id = NULL;
176
gchar* current_object_id = NULL;
181
181
gboolean label_sensitive;
182
182
gboolean label_visible;
183
183
guint32 image_type;
185
185
gboolean image_sensitive;
186
186
gboolean image_visible;
188
g_variant_get (result, "(a(sssbbusbb))", &iter);
189
while (g_variant_iter_loop (iter, "(sssbbusbb)",
188
g_variant_get(result, "(a(sssbbusbb))", &iter);
189
while (g_variant_iter_loop(iter, "(sssbbusbb)",
200
if (g_strcmp0(current_object_id, indicator_id) != 0)
200
if (g_strcmp0 (current_object_id, indicator_id) != 0)
203
g_free (current_object_id);
204
current_object_id = g_strdup (indicator_id);
203
g_free(current_object_id);
204
current_object_id = g_strdup(indicator_id);
207
g_free (current_object_id);
207
g_free(current_object_id);
213
get_n_entries_in_result (GVariant *result)
213
get_n_entries_in_result(GVariant* result)
220
220
gboolean label_sensitive;
221
221
gboolean label_visible;
222
222
guint32 image_type;
224
224
gboolean image_sensitive;
225
225
gboolean image_visible;
227
g_variant_get (result, "(a(sssbbusbb))", &iter);
228
while (g_variant_iter_loop (iter, "(sssbbusbb)",
239
if (g_strcmp0 (entry_id, "") != 0)
227
g_variant_get(result, "(a(sssbbusbb))", &iter);
228
while (g_variant_iter_loop(iter, "(sssbbusbb)",
239
if (g_strcmp0(entry_id, "") != 0)
248
248
//------------------------ /USEFUL FUNCTIONS ----------------------------------
250
static void TestAllocation (void);
251
static void TestIndicatorLoading (void);
252
static void TestEmptyIndicatorObject (void);
253
static void TestEntryAddition (void);
254
static void TestEntryActivateRequest (void);
250
static void TestAllocation(void);
251
static void TestIndicatorLoading(void);
252
static void TestEmptyIndicatorObject(void);
253
static void TestEntryAddition(void);
254
static void TestEntryActivateRequest(void);
257
TestPanelServiceCreateSuite ()
257
TestPanelServiceCreateSuite()
259
259
#define _DOMAIN "/Unit/PanelService"
261
g_test_add_func (_DOMAIN"/Allocation", TestAllocation);
262
g_test_add_func (_DOMAIN"/IndicatorLoading", TestIndicatorLoading);
263
g_test_add_func (_DOMAIN"/EmptyIndicatorObject", TestEmptyIndicatorObject);
264
g_test_add_func (_DOMAIN"/EntryAddition", TestEntryAddition);
265
g_test_add_func (_DOMAIN"/EntryActivateRequest", TestEntryActivateRequest);
271
PanelService *service;
273
service = panel_service_get_default ();
274
g_assert (PANEL_IS_SERVICE (service));
276
g_object_unref (service);
277
g_assert (PANEL_IS_SERVICE (service) == FALSE);
281
TestIndicatorLoading ()
283
PanelService *service;
284
IndicatorObject *object;
285
GList *objects = NULL;
287
object = test_object_new ();
288
g_assert (INDICATOR_IS_OBJECT (object));
289
objects = g_list_append (objects, object);
291
service = panel_service_get_default_with_indicators (objects);
292
g_assert (PANEL_IS_SERVICE (service));
294
g_assert_cmpint (panel_service_get_n_indicators (service), ==, 1);
296
g_list_free (objects);
297
g_object_unref (object);
298
g_object_unref (service);
302
TestEmptyIndicatorObject ()
304
PanelService *service;
305
IndicatorObject *object;
306
GList *objects = NULL;
309
object = test_object_new ();
310
g_assert (INDICATOR_IS_OBJECT (object));
311
objects = g_list_append (objects, object);
313
service = panel_service_get_default_with_indicators (objects);
314
g_assert (PANEL_IS_SERVICE (service));
316
g_assert_cmpint (panel_service_get_n_indicators (service), ==, 1);
318
result = panel_service_sync (service);
319
g_assert (result != NULL);
321
g_assert_cmpint (get_n_indicators_in_result (result), ==, 1);
323
g_variant_unref (result);
324
g_list_free (objects);
325
g_object_unref (object);
326
g_object_unref (service);
332
PanelService *service;
334
GList *objects = NULL;
261
g_test_add_func(_DOMAIN"/Allocation", TestAllocation);
262
g_test_add_func(_DOMAIN"/IndicatorLoading", TestIndicatorLoading);
263
g_test_add_func(_DOMAIN"/EmptyIndicatorObject", TestEmptyIndicatorObject);
264
g_test_add_func(_DOMAIN"/EntryAddition", TestEntryAddition);
265
g_test_add_func(_DOMAIN"/EntryActivateRequest", TestEntryActivateRequest);
271
PanelService* service;
273
service = panel_service_get_default();
274
g_assert(PANEL_IS_SERVICE(service));
276
g_object_unref(service);
277
g_assert(PANEL_IS_SERVICE(service) == FALSE);
281
TestIndicatorLoading()
283
PanelService* service;
284
IndicatorObject* object;
285
GList* objects = NULL;
287
object = test_object_new();
288
g_assert(INDICATOR_IS_OBJECT(object));
289
objects = g_list_append(objects, object);
291
service = panel_service_get_default_with_indicators(objects);
292
g_assert(PANEL_IS_SERVICE(service));
294
g_assert_cmpint(panel_service_get_n_indicators(service), == , 1);
296
g_list_free(objects);
297
g_object_unref(object);
298
g_object_unref(service);
302
TestEmptyIndicatorObject()
304
PanelService* service;
305
IndicatorObject* object;
306
GList* objects = NULL;
309
object = test_object_new();
310
g_assert(INDICATOR_IS_OBJECT(object));
311
objects = g_list_append(objects, object);
313
service = panel_service_get_default_with_indicators(objects);
314
g_assert(PANEL_IS_SERVICE(service));
316
g_assert_cmpint(panel_service_get_n_indicators(service), == , 1);
318
result = panel_service_sync(service);
319
g_assert(result != NULL);
321
g_assert_cmpint(get_n_indicators_in_result(result), == , 1);
323
g_variant_unref(result);
324
g_list_free(objects);
325
g_object_unref(object);
326
g_object_unref(service);
332
PanelService* service;
334
GList* objects = NULL;
338
object = (TestObject *)test_object_new ();
339
test_object_add_entry (object, "Hello", "gtk-apply");
340
g_assert (INDICATOR_IS_OBJECT (object));
341
objects = g_list_append (objects, object);
343
service = panel_service_get_default_with_indicators (objects);
344
g_assert (PANEL_IS_SERVICE (service));
346
result = panel_service_sync (service);
347
g_assert (result != NULL);
348
g_assert_cmpint (get_n_entries_in_result (result), ==, 1);
338
object = (TestObject*)test_object_new();
339
test_object_add_entry(object, "Hello", "gtk-apply");
340
g_assert(INDICATOR_IS_OBJECT(object));
341
objects = g_list_append(objects, object);
343
service = panel_service_get_default_with_indicators(objects);
344
g_assert(PANEL_IS_SERVICE(service));
346
result = panel_service_sync(service);
347
g_assert(result != NULL);
348
g_assert_cmpint(get_n_entries_in_result(result), == , 1);
350
350
for (i = 2; i < 10; i++)
352
g_variant_unref (result);
354
test_object_add_entry (object, "Bye", "gtk-forward");
355
result = panel_service_sync (service);
356
g_assert_cmpint (get_n_entries_in_result (result), ==, i);
359
g_variant_unref (result);
360
g_list_free (objects);
361
g_object_unref (object);
362
g_object_unref (service);
366
OnEntryActivateRequest (IndicatorObject *object,
367
const gchar *entry_id,
368
const gchar *entry_id_should_be)
370
g_assert_cmpstr (entry_id, ==, entry_id_should_be);
374
TestEntryActivateRequest ()
376
PanelService *service;
378
GList *objects = NULL;
379
IndicatorObjectEntry *entry;
382
object = (TestObject *)test_object_new ();
383
entry = test_object_add_entry (object, "Hello", "gtk-apply");
384
id = g_strdup_printf ("%p", entry);
385
g_assert (INDICATOR_IS_OBJECT (object));
386
objects = g_list_append (objects, object);
388
service = panel_service_get_default_with_indicators (objects);
389
g_assert (PANEL_IS_SERVICE (service));
391
g_signal_connect (service, "entry-activate-request",
392
G_CALLBACK (OnEntryActivateRequest),
395
test_object_show_entry (object, entry, 1234);
398
g_list_free (objects);
399
g_object_unref (object);
400
g_object_unref (service);
352
g_variant_unref(result);
354
test_object_add_entry(object, "Bye", "gtk-forward");
355
result = panel_service_sync(service);
356
g_assert_cmpint(get_n_entries_in_result(result), == , i);
359
g_variant_unref(result);
360
g_list_free(objects);
361
g_object_unref(object);
362
g_object_unref(service);
366
OnEntryActivateRequest(IndicatorObject* object,
367
const gchar* entry_id,
368
const gchar* entry_id_should_be)
370
g_assert_cmpstr(entry_id, == , entry_id_should_be);
374
TestEntryActivateRequest()
376
PanelService* service;
378
GList* objects = NULL;
379
IndicatorObjectEntry* entry;
382
object = (TestObject*)test_object_new();
383
entry = test_object_add_entry(object, "Hello", "gtk-apply");
384
id = g_strdup_printf("%p", entry);
385
g_assert(INDICATOR_IS_OBJECT(object));
386
objects = g_list_append(objects, object);
388
service = panel_service_get_default_with_indicators(objects);
389
g_assert(PANEL_IS_SERVICE(service));
391
g_signal_connect(service, "entry-activate-request",
392
G_CALLBACK(OnEntryActivateRequest),
395
test_object_show_entry(object, entry, 1234);
398
g_list_free(objects);
399
g_object_unref(object);
400
g_object_unref(service);