| 118 static void |
118 static void |
| 119 test_purple_person_avatar_for_display_person(void) { |
119 test_purple_person_avatar_for_display_person(void) { |
| 120 PurpleContactInfo *info = NULL; |
120 PurpleContactInfo *info = NULL; |
| 121 PurplePerson *person = NULL; |
121 PurplePerson *person = NULL; |
| 122 GdkPixbuf *avatar = NULL; |
122 GdkPixbuf *avatar = NULL; |
| 123 |
123 guint called = 0; |
| 124 person = purple_person_new(); |
124 |
| |
125 person = purple_person_new(); |
| |
126 g_signal_connect(person, "notify::avatar", |
| |
127 G_CALLBACK(test_purple_person_notify_cb), &called); |
| |
128 g_signal_connect(person, "notify::avatar-for-display", |
| |
129 G_CALLBACK(test_purple_person_notify_cb), &called); |
| 125 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
130 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
| 126 purple_person_set_avatar(person, avatar); |
131 purple_person_set_avatar(person, avatar); |
| |
132 g_assert_cmpuint(called, ==, 2); |
| 127 |
133 |
| 128 info = purple_contact_info_new("id"); |
134 info = purple_contact_info_new("id"); |
| 129 purple_person_add_contact_info(person, info); |
135 purple_person_add_contact_info(person, info); |
| 130 |
136 |
| 131 /* Make sure the person's alias is overriding the contact info. */ |
137 /* Make sure the person's avatar is overriding the contact info. */ |
| 132 g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
138 g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
| 133 |
139 |
| 134 g_clear_object(&info); |
140 g_clear_object(&info); |
| 135 g_clear_object(&person); |
141 g_clear_object(&person); |
| 136 g_clear_object(&avatar); |
142 g_clear_object(&avatar); |
| 139 static void |
145 static void |
| 140 test_purple_person_avatar_for_display_contact(void) { |
146 test_purple_person_avatar_for_display_contact(void) { |
| 141 PurpleContactInfo *info = NULL; |
147 PurpleContactInfo *info = NULL; |
| 142 PurplePerson *person = NULL; |
148 PurplePerson *person = NULL; |
| 143 GdkPixbuf *avatar = NULL; |
149 GdkPixbuf *avatar = NULL; |
| 144 |
150 guint called = 0; |
| 145 person = purple_person_new(); |
151 |
| |
152 person = purple_person_new(); |
| |
153 g_signal_connect(person, "notify::avatar-for-display", |
| |
154 G_CALLBACK(test_purple_person_notify_cb), &called); |
| 146 |
155 |
| 147 info = purple_contact_info_new("id"); |
156 info = purple_contact_info_new("id"); |
| 148 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
157 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
| 149 purple_contact_info_set_avatar(info, avatar); |
158 purple_contact_info_set_avatar(info, avatar); |
| 150 purple_person_add_contact_info(person, info); |
159 purple_person_add_contact_info(person, info); |
| |
160 g_assert_cmpuint(called, ==, 1); |
| 151 |
161 |
| 152 /* Make sure the person's alias is overriding the contact info. */ |
162 /* Make sure the person's alias is overriding the contact info. */ |
| 153 g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
163 g_assert_true(purple_person_get_avatar_for_display(person) == avatar); |
| |
164 g_clear_object(&avatar); |
| |
165 |
| |
166 /* Now change the avatar on the contact info an verify that we not notified |
| |
167 * of the property changing. |
| |
168 */ |
| |
169 called = 0; |
| |
170 avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1); |
| |
171 purple_contact_info_set_avatar(info, avatar); |
| |
172 g_assert_cmpuint(called, ==, 1); |
| 154 |
173 |
| 155 g_clear_object(&info); |
174 g_clear_object(&info); |
| 156 g_clear_object(&person); |
175 g_clear_object(&person); |
| 157 g_clear_object(&avatar); |
176 g_clear_object(&avatar); |
| 158 } |
177 } |
| 178 |
197 |
| 179 static void |
198 static void |
| 180 test_purple_person_name_for_display_contact(void) { |
199 test_purple_person_name_for_display_contact(void) { |
| 181 PurpleContactInfo *info = NULL; |
200 PurpleContactInfo *info = NULL; |
| 182 PurplePerson *person = NULL; |
201 PurplePerson *person = NULL; |
| 183 |
202 guint called = 0; |
| 184 person = purple_person_new(); |
203 |
| |
204 person = purple_person_new(); |
| |
205 g_signal_connect(person, "notify::name-for-display", |
| |
206 G_CALLBACK(test_purple_person_notify_cb), &called); |
| 185 |
207 |
| 186 info = purple_contact_info_new("id"); |
208 info = purple_contact_info_new("id"); |
| 187 purple_person_add_contact_info(person, info); |
209 purple_person_add_contact_info(person, info); |
| 188 |
210 g_assert_cmpuint(called, ==, 1); |
| 189 /* Make sure the contact info's name for display is called when the |
211 |
| 190 * person's alias is unset. |
212 /* Make sure the name for display matches the id of the contact. */ |
| |
213 g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "id"); |
| |
214 |
| |
215 /* Now set a username on the contact and verify that the name for display |
| |
216 * matches and that the notify signal was emitted for the property. |
| 191 */ |
217 */ |
| 192 g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "id"); |
218 purple_contact_info_set_username(info, "clu"); |
| |
219 g_assert_cmpstr(purple_person_get_name_for_display(person), ==, "clu"); |
| |
220 g_assert_cmpuint(called, ==, 2); |
| 193 |
221 |
| 194 g_clear_object(&info); |
222 g_clear_object(&info); |
| 195 g_clear_object(&person); |
223 g_clear_object(&person); |
| 196 } |
224 } |
| 197 |
225 |
| 304 test_purple_person_priority_single(void) { |
332 test_purple_person_priority_single(void) { |
| 305 PurpleContactInfo *info = NULL; |
333 PurpleContactInfo *info = NULL; |
| 306 PurpleContactInfo *priority = NULL; |
334 PurpleContactInfo *priority = NULL; |
| 307 PurplePerson *person = NULL; |
335 PurplePerson *person = NULL; |
| 308 PurplePresence *presence = NULL; |
336 PurplePresence *presence = NULL; |
| 309 PurpleStatus *status = NULL; |
337 guint called = 0; |
| 310 PurpleStatusType *status_type = NULL; |
|
| 311 gboolean called = FALSE; |
|
| 312 |
338 |
| 313 person = purple_person_new(); |
339 person = purple_person_new(); |
| 314 g_signal_connect(person, "notify::priority-contact-info", |
340 g_signal_connect(person, "notify::priority-contact-info", |
| 315 G_CALLBACK(test_purple_person_notify_cb), &called); |
341 G_CALLBACK(test_purple_person_notify_cb), &called); |
| 316 priority = purple_person_get_priority_contact_info(person); |
342 priority = purple_person_get_priority_contact_info(person); |
| 318 |
344 |
| 319 /* Now create a real contact. */ |
345 /* Now create a real contact. */ |
| 320 info = purple_contact_info_new(NULL); |
346 info = purple_contact_info_new(NULL); |
| 321 purple_person_add_contact_info(person, info); |
347 purple_person_add_contact_info(person, info); |
| 322 |
348 |
| 323 /* Set the status of the contact. */ |
349 /* Set the presence of the contact. */ |
| 324 presence = purple_contact_info_get_presence(info); |
350 presence = purple_contact_info_get_presence(info); |
| 325 status_type = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", |
351 purple_presence_set_primitive(presence, |
| 326 "Available", FALSE); |
352 PURPLE_PRESENCE_PRIMITIVE_AVAILABLE); |
| 327 status = purple_status_new(status_type, presence); |
353 |
| 328 g_object_set(G_OBJECT(presence), "active-status", status, NULL); |
354 g_assert_cmpuint(called, ==, 1); |
| 329 g_clear_object(&status); |
|
| 330 |
|
| 331 g_assert_true(called); |
|
| 332 |
355 |
| 333 priority = purple_person_get_priority_contact_info(person); |
356 priority = purple_person_get_priority_contact_info(person); |
| 334 g_assert_true(priority == info); |
357 g_assert_true(priority == info); |
| 335 |
358 |
| 336 purple_status_type_destroy(status_type); |
|
| 337 g_clear_object(&person); |
359 g_clear_object(&person); |
| 338 g_clear_object(&info); |
360 g_clear_object(&info); |
| 339 g_clear_object(&presence); |
361 g_clear_object(&presence); |
| 340 } |
362 } |
| 341 |
363 |
| 344 PurpleContactInfo *priority = NULL; |
366 PurpleContactInfo *priority = NULL; |
| 345 PurpleContactInfo *first = NULL; |
367 PurpleContactInfo *first = NULL; |
| 346 PurpleContactInfo *sorted_contact = NULL; |
368 PurpleContactInfo *sorted_contact = NULL; |
| 347 PurplePerson *person = NULL; |
369 PurplePerson *person = NULL; |
| 348 PurplePresence *sorted_presence = NULL; |
370 PurplePresence *sorted_presence = NULL; |
| 349 PurpleStatus *status = NULL; |
371 guint called = 0; |
| 350 PurpleStatusType *available = NULL; |
|
| 351 PurpleStatusType *offline = NULL; |
|
| 352 gboolean changed = FALSE; |
|
| 353 gint n_infos = 5; |
372 gint n_infos = 5; |
| 354 guint n_items = 0; |
373 guint n_items = 0; |
| 355 |
374 |
| 356 /* This unit test is a bit complicated, but it adds 5 contact infos to a |
375 /* This unit test is a bit complicated, but it adds 5 contact infos to a |
| 357 * person all whose presences are set to offline. After adding all the |
376 * person all whose presences are set to offline. After adding all the |
| 359 * priority contact info. Then we flip the active status of the n_infos - 2 |
378 * priority contact info. Then we flip the active status of the n_infos - 2 |
| 360 * infos to available. This should make it the priority contact info which |
379 * infos to available. This should make it the priority contact info which |
| 361 * we then assert. |
380 * we then assert. |
| 362 */ |
381 */ |
| 363 |
382 |
| 364 /* Create our status types. */ |
|
| 365 available = purple_status_type_new(PURPLE_STATUS_AVAILABLE, "available", |
|
| 366 "Available", FALSE); |
|
| 367 offline = purple_status_type_new(PURPLE_STATUS_OFFLINE, "offline", |
|
| 368 "Offline", FALSE); |
|
| 369 |
|
| 370 /* Create the person and connected to the notify signal for the |
383 /* Create the person and connected to the notify signal for the |
| 371 * priority-contact property. |
384 * priority-contact property. |
| 372 */ |
385 */ |
| 373 person = purple_person_new(); |
386 person = purple_person_new(); |
| 374 g_signal_connect(person, "notify::priority-contact-info", |
387 g_signal_connect(person, "notify::priority-contact-info", |
| 375 G_CALLBACK(test_purple_person_notify_cb), &changed); |
388 G_CALLBACK(test_purple_person_notify_cb), &called); |
| 376 priority = purple_person_get_priority_contact_info(person); |
389 priority = purple_person_get_priority_contact_info(person); |
| 377 g_assert_null(priority); |
390 g_assert_null(priority); |
| 378 |
391 |
| 379 /* Create and add all contact infos. */ |
392 /* Create and add all contact infos. */ |
| 380 for(gint i = 0; i < n_infos; i++) { |
393 for(gint i = 0; i < n_infos; i++) { |
| 381 PurpleContactInfo *info = NULL; |
394 PurpleContactInfo *info = NULL; |
| 382 PurplePresence *presence = NULL; |
|
| 383 gchar *username = NULL; |
395 gchar *username = NULL; |
| 384 |
396 |
| 385 /* Set changed to false as it shouldn't be changed. */ |
397 /* Set called to 0 as it shouldn't be called as the priority contact |
| 386 changed = FALSE; |
398 * info shouldn't change except for the first index. |
| |
399 */ |
| |
400 called = 0; |
| 387 |
401 |
| 388 /* Now create a real contact. */ |
402 /* Now create a real contact. */ |
| 389 username = g_strdup_printf("username%d", i + 1); |
403 username = g_strdup_printf("username%d", i + 1); |
| 390 info = purple_contact_info_new(NULL); |
404 info = purple_contact_info_new(NULL); |
| 391 purple_contact_info_set_username(info, username); |
405 purple_contact_info_set_username(info, username); |
| 392 g_free(username); |
406 g_free(username); |
| 393 |
407 |
| 394 /* Set the status for the contact. */ |
|
| 395 presence = purple_contact_info_get_presence(info); |
|
| 396 status = purple_status_new(offline, presence); |
|
| 397 g_object_set(G_OBJECT(presence), "active-status", status, NULL); |
|
| 398 g_clear_object(&status); |
|
| 399 |
|
| 400 purple_person_add_contact_info(person, info); |
408 purple_person_add_contact_info(person, info); |
| 401 |
409 |
| 402 if(i == 0) { |
410 if(i == 0) { |
| 403 first = g_object_ref(info); |
411 first = g_object_ref(info); |
| 404 g_assert_true(changed); |
412 g_assert_cmpuint(called, ==, 1); |
| 405 } else { |
413 } else { |
| 406 g_assert_false(changed); |
414 g_assert_cmpuint(called, ==, 0); |
| 407 |
415 |
| 408 if(i == n_infos - 2) { |
416 if(i == n_infos - 2) { |
| |
417 PurplePresence *presence = NULL; |
| |
418 |
| |
419 /* Add a reference to the presence of this specific contact |
| |
420 * info, as we want to tweak it later. |
| |
421 */ |
| |
422 presence = purple_contact_info_get_presence(info); |
| |
423 sorted_presence = g_object_ref(presence); |
| |
424 |
| 409 sorted_contact = g_object_ref(info); |
425 sorted_contact = g_object_ref(info); |
| 410 sorted_presence = g_object_ref(presence); |
|
| 411 } |
426 } |
| 412 } |
427 } |
| 413 |
428 |
| 414 g_clear_object(&info); |
429 g_clear_object(&info); |
| 415 } |
430 } |
| 422 g_clear_object(&first); |
437 g_clear_object(&first); |
| 423 |
438 |
| 424 /* Now set the second from the last contact info's status to available, and |
439 /* Now set the second from the last contact info's status to available, and |
| 425 * verify that that contact info is now the priority contact info. |
440 * verify that that contact info is now the priority contact info. |
| 426 */ |
441 */ |
| 427 changed = FALSE; |
442 called = 0; |
| 428 status = purple_status_new(available, sorted_presence); |
443 purple_presence_set_primitive(sorted_presence, |
| 429 g_object_set(G_OBJECT(sorted_presence), "active-status", status, NULL); |
444 PURPLE_PRESENCE_PRIMITIVE_AVAILABLE); |
| 430 g_clear_object(&status); |
|
| 431 g_assert_true(changed); |
|
| 432 priority = purple_person_get_priority_contact_info(person); |
445 priority = purple_person_get_priority_contact_info(person); |
| 433 g_assert_true(priority == sorted_contact); |
446 g_assert_true(priority == sorted_contact); |
| |
447 g_assert_cmpuint(called, ==, 1); |
| 434 |
448 |
| 435 /* Cleanup. */ |
449 /* Cleanup. */ |
| 436 purple_status_type_destroy(offline); |
|
| 437 purple_status_type_destroy(available); |
|
| 438 |
|
| 439 g_clear_object(&sorted_contact); |
450 g_clear_object(&sorted_contact); |
| 440 g_clear_object(&sorted_presence); |
451 g_clear_object(&sorted_presence); |
| 441 |
452 |
| 442 g_clear_object(&person); |
453 g_clear_object(&person); |
| 443 } |
454 } |