From a2e95f155e746d390a8e6b5253d527a655df96a2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 17:07:29 -0500 Subject: Adding a test to set the label and guides a bunch. --- tests/test-libappindicator.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests/test-libappindicator.c') diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c index 86879b3..6d06236 100644 --- a/tests/test-libappindicator.c +++ b/tests/test-libappindicator.c @@ -162,6 +162,68 @@ test_libappindicator_init (void) return; } +void +test_libappindicator_set_label (void) +{ + AppIndicator * ci = app_indicator_new ("my-id", + "my-name", + APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + + g_assert(ci != NULL); + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + /* First check all the clearing modes, this is important as + we're going to use them later, we need them to work. */ + app_indicator_set_label(ci, NULL, NULL); + + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, "", NULL); + + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, NULL, ""); + + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, "", ""); + + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, "label", ""); + + g_assert(g_strcmp0(app_indicator_get_label(ci), "label")); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, NULL, NULL); + + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + app_indicator_set_label(ci, "label", "guide"); + + g_assert(g_strcmp0(app_indicator_get_label(ci), "label")); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide")); + + app_indicator_set_label(ci, "label2", "guide"); + + g_assert(g_strcmp0(app_indicator_get_label(ci), "label2")); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide")); + + app_indicator_set_label(ci, "trick-label", "trick-guide"); + + g_assert(g_strcmp0(app_indicator_get_label(ci), "trick-label")); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "trick-guide")); + + g_object_unref(G_OBJECT(ci)); + return; +} + void test_libappindicator_props_suite (void) { @@ -169,6 +231,7 @@ test_libappindicator_props_suite (void) g_test_add_func ("/indicator-application/libappindicator/init_props", test_libappindicator_init_with_props); g_test_add_func ("/indicator-application/libappindicator/init_set_props", test_libappindicator_init_set_props); g_test_add_func ("/indicator-application/libappindicator/prop_signals", test_libappindicator_prop_signals); + g_test_add_func ("/indicator-application/libappindicator/set_label", test_libappindicator_set_label); return; } -- cgit v1.2.3 From 29253842cb7715e7f3d3ca94bf4082edb824bb9c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 17:14:32 -0500 Subject: Stupid reverse logic in the string comparison. --- tests/test-libappindicator.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/test-libappindicator.c') diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c index 6d06236..2ac7326 100644 --- a/tests/test-libappindicator.c +++ b/tests/test-libappindicator.c @@ -197,7 +197,7 @@ test_libappindicator_set_label (void) app_indicator_set_label(ci, "label", ""); - g_assert(g_strcmp0(app_indicator_get_label(ci), "label")); + g_assert(g_strcmp0(app_indicator_get_label(ci), "label") == 0); g_assert(app_indicator_get_label_guide(ci) == NULL); app_indicator_set_label(ci, NULL, NULL); @@ -207,18 +207,18 @@ test_libappindicator_set_label (void) app_indicator_set_label(ci, "label", "guide"); - g_assert(g_strcmp0(app_indicator_get_label(ci), "label")); - g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide")); + g_assert(g_strcmp0(app_indicator_get_label(ci), "label") == 0); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide") == 0); app_indicator_set_label(ci, "label2", "guide"); - g_assert(g_strcmp0(app_indicator_get_label(ci), "label2")); - g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide")); + g_assert(g_strcmp0(app_indicator_get_label(ci), "label2") == 0); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide") == 0); app_indicator_set_label(ci, "trick-label", "trick-guide"); - g_assert(g_strcmp0(app_indicator_get_label(ci), "trick-label")); - g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "trick-guide")); + g_assert(g_strcmp0(app_indicator_get_label(ci), "trick-label") == 0); + g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "trick-guide") == 0); g_object_unref(G_OBJECT(ci)); return; -- cgit v1.2.3 From 6882b4cb557db5bc65f14d6b6e88f8f9667896b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 21:09:58 -0500 Subject: Setting up a basic signals test --- tests/test-libappindicator.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/test-libappindicator.c') diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c index 2ac7326..e6c8dcc 100644 --- a/tests/test-libappindicator.c +++ b/tests/test-libappindicator.c @@ -224,6 +224,47 @@ test_libappindicator_set_label (void) return; } +void +label_signals_cb (AppIndicator * appindicator, gchar * label, gchar * guide, gpointer user_data) +{ + gint * label_signals_count = (gint *)user_data; + (*label_signals_count)++; + return; +} + +void +label_signals_check (void) +{ + while (g_main_context_pending(NULL)) { + g_main_context_iteration(NULL, TRUE); + } + + return; +} + +void +test_libappindicator_label_signals (void) +{ + gint label_signals_count = 0; + AppIndicator * ci = app_indicator_new ("my-id", + "my-name", + APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + + g_assert(ci != NULL); + g_assert(app_indicator_get_label(ci) == NULL); + g_assert(app_indicator_get_label_guide(ci) == NULL); + + g_signal_connect(G_OBJECT(ci), APP_INDICATOR_SIGNAL_NEW_LABEL, G_CALLBACK(label_signals_cb), &label_signals_count); + + app_indicator_set_label(ci, "label", "guide"); + g_assert(label_signals_count == 0); + + label_signals_check(); + g_assert(label_signals_count == 1); + + return; +} + void test_libappindicator_props_suite (void) { @@ -232,6 +273,7 @@ test_libappindicator_props_suite (void) g_test_add_func ("/indicator-application/libappindicator/init_set_props", test_libappindicator_init_set_props); g_test_add_func ("/indicator-application/libappindicator/prop_signals", test_libappindicator_prop_signals); g_test_add_func ("/indicator-application/libappindicator/set_label", test_libappindicator_set_label); + g_test_add_func ("/indicator-application/libappindicator/label_signals", test_libappindicator_label_signals); return; } -- cgit v1.2.3 From 43e185e0c4828a5eaa0422186198d08edefd12a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 21:13:34 -0500 Subject: More signalling tests. --- tests/test-libappindicator.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/test-libappindicator.c') diff --git a/tests/test-libappindicator.c b/tests/test-libappindicator.c index e6c8dcc..8d12ac5 100644 --- a/tests/test-libappindicator.c +++ b/tests/test-libappindicator.c @@ -256,9 +256,37 @@ test_libappindicator_label_signals (void) g_signal_connect(G_OBJECT(ci), APP_INDICATOR_SIGNAL_NEW_LABEL, G_CALLBACK(label_signals_cb), &label_signals_count); + /* Shouldn't be a signal as it should be stuck in idle */ app_indicator_set_label(ci, "label", "guide"); g_assert(label_signals_count == 0); + /* Should show up after idle processing */ + label_signals_check(); + g_assert(label_signals_count == 1); + + /* Shouldn't signal with no change */ + label_signals_count = 0; + app_indicator_set_label(ci, "label", "guide"); + label_signals_check(); + g_assert(label_signals_count == 0); + + /* Change one, we should get one signal */ + app_indicator_set_label(ci, "label2", "guide"); + label_signals_check(); + g_assert(label_signals_count == 1); + + /* Change several times, one signal */ + label_signals_count = 0; + app_indicator_set_label(ci, "label1", "guide0"); + app_indicator_set_label(ci, "label1", "guide1"); + app_indicator_set_label(ci, "label2", "guide2"); + app_indicator_set_label(ci, "label3", "guide3"); + label_signals_check(); + g_assert(label_signals_count == 1); + + /* Clear should signal too */ + label_signals_count = 0; + app_indicator_set_label(ci, NULL, NULL); label_signals_check(); g_assert(label_signals_count == 1); -- cgit v1.2.3