~ubuntu-branches/ubuntu/maverick/indicator-application/maverick-proposed

« back to all changes in this revision

Viewing changes to tests/test-libappindicator.c

  • Committer: Bazaar Package Importer
  • Author(s): Ted Gould
  • Date: 2010-08-12 13:57:17 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20100812135717-by6moch4zgwnv6js
Tags: 0.2.4-0ubuntu1
* New upstream release.
  * Add in ordering IDs
  * Adding label support into the library
  * Adding label support into the indicator
  * Breaking the ABI in order to get more space in the class
    structure.
  * Allow the icon theme path to be changed dynamically (LP: #607831)
* debian/control: Moving libappindicator0 to libappindicator1
* debian/rules: Moving libappindicator0 to libappindicator1

Show diffs side-by-side

added added

removed removed

Lines of Context:
163
163
}
164
164
 
165
165
void
 
166
test_libappindicator_set_label (void)
 
167
{
 
168
        AppIndicator * ci = app_indicator_new ("my-id",
 
169
                                               "my-name",
 
170
                                               APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
 
171
 
 
172
        g_assert(ci != NULL);
 
173
        g_assert(app_indicator_get_label(ci) == NULL);
 
174
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
175
 
 
176
        /* First check all the clearing modes, this is important as
 
177
           we're going to use them later, we need them to work. */
 
178
        app_indicator_set_label(ci, NULL, NULL);
 
179
 
 
180
        g_assert(app_indicator_get_label(ci) == NULL);
 
181
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
182
 
 
183
        app_indicator_set_label(ci, "", NULL);
 
184
 
 
185
        g_assert(app_indicator_get_label(ci) == NULL);
 
186
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
187
 
 
188
        app_indicator_set_label(ci, NULL, "");
 
189
 
 
190
        g_assert(app_indicator_get_label(ci) == NULL);
 
191
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
192
 
 
193
        app_indicator_set_label(ci, "", "");
 
194
 
 
195
        g_assert(app_indicator_get_label(ci) == NULL);
 
196
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
197
 
 
198
        app_indicator_set_label(ci, "label", "");
 
199
 
 
200
        g_assert(g_strcmp0(app_indicator_get_label(ci), "label") == 0);
 
201
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
202
 
 
203
        app_indicator_set_label(ci, NULL, NULL);
 
204
 
 
205
        g_assert(app_indicator_get_label(ci) == NULL);
 
206
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
207
 
 
208
        app_indicator_set_label(ci, "label", "guide");
 
209
 
 
210
        g_assert(g_strcmp0(app_indicator_get_label(ci), "label") == 0);
 
211
        g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide") == 0);
 
212
 
 
213
        app_indicator_set_label(ci, "label2", "guide");
 
214
 
 
215
        g_assert(g_strcmp0(app_indicator_get_label(ci), "label2") == 0);
 
216
        g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "guide") == 0);
 
217
 
 
218
        app_indicator_set_label(ci, "trick-label", "trick-guide");
 
219
 
 
220
        g_assert(g_strcmp0(app_indicator_get_label(ci), "trick-label") == 0);
 
221
        g_assert(g_strcmp0(app_indicator_get_label_guide(ci), "trick-guide") == 0);
 
222
 
 
223
        g_object_unref(G_OBJECT(ci));
 
224
        return;
 
225
}
 
226
 
 
227
void
 
228
label_signals_cb (AppIndicator * appindicator, gchar * label, gchar * guide, gpointer user_data)
 
229
{
 
230
        gint * label_signals_count = (gint *)user_data;
 
231
        (*label_signals_count)++;
 
232
        return;
 
233
}
 
234
 
 
235
void
 
236
label_signals_check (void)
 
237
{
 
238
        while (g_main_context_pending(NULL)) {
 
239
                g_main_context_iteration(NULL, TRUE);
 
240
        }
 
241
 
 
242
        return;
 
243
}
 
244
 
 
245
void
 
246
test_libappindicator_label_signals (void)
 
247
{
 
248
        gint label_signals_count = 0;
 
249
        AppIndicator * ci = app_indicator_new ("my-id",
 
250
                                               "my-name",
 
251
                                               APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
 
252
 
 
253
        g_assert(ci != NULL);
 
254
        g_assert(app_indicator_get_label(ci) == NULL);
 
255
        g_assert(app_indicator_get_label_guide(ci) == NULL);
 
256
 
 
257
        g_signal_connect(G_OBJECT(ci), APP_INDICATOR_SIGNAL_NEW_LABEL, G_CALLBACK(label_signals_cb), &label_signals_count);
 
258
 
 
259
        /* Shouldn't be a signal as it should be stuck in idle */
 
260
        app_indicator_set_label(ci, "label", "guide");
 
261
        g_assert(label_signals_count == 0);
 
262
 
 
263
        /* Should show up after idle processing */
 
264
        label_signals_check();
 
265
        g_assert(label_signals_count == 1);
 
266
 
 
267
        /* Shouldn't signal with no change */
 
268
        label_signals_count = 0;
 
269
        app_indicator_set_label(ci, "label", "guide");
 
270
        label_signals_check();
 
271
        g_assert(label_signals_count == 0);
 
272
 
 
273
        /* Change one, we should get one signal */
 
274
        app_indicator_set_label(ci, "label2", "guide");
 
275
        label_signals_check();
 
276
        g_assert(label_signals_count == 1);
 
277
 
 
278
        /* Change several times, one signal */
 
279
        label_signals_count = 0;
 
280
        app_indicator_set_label(ci, "label1", "guide0");
 
281
        app_indicator_set_label(ci, "label1", "guide1");
 
282
        app_indicator_set_label(ci, "label2", "guide2");
 
283
        app_indicator_set_label(ci, "label3", "guide3");
 
284
        label_signals_check();
 
285
        g_assert(label_signals_count == 1);
 
286
 
 
287
        /* Clear should signal too */
 
288
        label_signals_count = 0;
 
289
        app_indicator_set_label(ci, NULL, NULL);
 
290
        label_signals_check();
 
291
        g_assert(label_signals_count == 1);
 
292
 
 
293
        return;
 
294
}
 
295
 
 
296
void
166
297
test_libappindicator_props_suite (void)
167
298
{
168
299
        g_test_add_func ("/indicator-application/libappindicator/init",            test_libappindicator_init);
169
300
        g_test_add_func ("/indicator-application/libappindicator/init_props",      test_libappindicator_init_with_props);
170
301
        g_test_add_func ("/indicator-application/libappindicator/init_set_props",  test_libappindicator_init_set_props);
171
302
        g_test_add_func ("/indicator-application/libappindicator/prop_signals",    test_libappindicator_prop_signals);
 
303
        g_test_add_func ("/indicator-application/libappindicator/set_label",       test_libappindicator_set_label);
 
304
        g_test_add_func ("/indicator-application/libappindicator/label_signals",   test_libappindicator_label_signals);
172
305
 
173
306
        return;
174
307
}