| 345 |
345 |
| 346 g_clear_object(&account); |
346 g_clear_object(&account); |
| 347 g_clear_object(&buddy); |
347 g_clear_object(&buddy); |
| 348 g_clear_object(&contact); |
348 g_clear_object(&contact); |
| 349 } |
349 } |
| |
350 |
| |
351 /****************************************************************************** |
| |
352 * Person Tests |
| |
353 *****************************************************************************/ |
| |
354 static void |
| |
355 test_purple_contact_manager_person_add_remove(void) { |
| |
356 PurpleContactManager *manager = NULL; |
| |
357 PurplePerson *person = NULL; |
| |
358 GListModel *model = NULL; |
| |
359 int added_called = 0; |
| |
360 int removed_called = 0; |
| |
361 |
| |
362 manager = g_object_new(PURPLE_TYPE_CONTACT_MANAGER, NULL); |
| |
363 model = G_LIST_MODEL(manager); |
| |
364 |
| |
365 g_assert_true(PURPLE_IS_CONTACT_MANAGER(manager)); |
| |
366 |
| |
367 /* Wire up our signals. */ |
| |
368 g_signal_connect(manager, "person-added", |
| |
369 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
370 &added_called); |
| |
371 g_signal_connect(manager, "person-removed", |
| |
372 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
373 &removed_called); |
| |
374 |
| |
375 /* Create the person and add it to the manager. */ |
| |
376 person = purple_person_new(); |
| |
377 purple_contact_manager_add_person(manager, person); |
| |
378 |
| |
379 /* Make sure the person is available. */ |
| |
380 g_assert_cmpuint(g_list_model_get_n_items(model), ==, 1); |
| |
381 |
| |
382 /* Make sure the added signal was called. */ |
| |
383 g_assert_cmpint(added_called, ==, 1); |
| |
384 |
| |
385 /* Remove the contact. */ |
| |
386 purple_contact_manager_remove_person(manager, person, FALSE); |
| |
387 g_assert_cmpint(removed_called, ==, 1); |
| |
388 |
| |
389 /* Make sure the person was removed. */ |
| |
390 g_assert_cmpuint(g_list_model_get_n_items(model), ==, 0); |
| |
391 |
| |
392 /* Clean up.*/ |
| |
393 g_clear_object(&person); |
| |
394 g_clear_object(&manager); |
| |
395 } |
| |
396 |
| |
397 static void |
| |
398 test_purple_contact_manager_person_add_via_contact_remove_person_with_contacts(void) |
| |
399 { |
| |
400 PurpleAccount *account = NULL; |
| |
401 PurpleContact *contact = NULL; |
| |
402 PurpleContactManager *manager = NULL; |
| |
403 PurplePerson *person = NULL; |
| |
404 GListModel *contacts = NULL; |
| |
405 GListModel *model = NULL; |
| |
406 int contact_added_called = 0; |
| |
407 int contact_removed_called = 0; |
| |
408 int person_added_called = 0; |
| |
409 int person_removed_called = 0; |
| |
410 |
| |
411 manager = g_object_new(PURPLE_TYPE_CONTACT_MANAGER, NULL); |
| |
412 model = G_LIST_MODEL(manager); |
| |
413 |
| |
414 g_assert_true(PURPLE_IS_CONTACT_MANAGER(manager)); |
| |
415 |
| |
416 /* Wire up our signals. */ |
| |
417 g_signal_connect(manager, "added", |
| |
418 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
419 &contact_added_called); |
| |
420 g_signal_connect(manager, "removed", |
| |
421 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
422 &contact_removed_called); |
| |
423 g_signal_connect(manager, "person-added", |
| |
424 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
425 &person_added_called); |
| |
426 g_signal_connect(manager, "person-removed", |
| |
427 G_CALLBACK(test_purple_contact_manager_increment_cb), |
| |
428 &person_removed_called); |
| |
429 |
| |
430 /* Create all of our objects. */ |
| |
431 account = purple_account_new("test", "test"); |
| |
432 contact = purple_contact_new(account, "foo"); |
| |
433 person = purple_person_new(); |
| |
434 purple_person_add_contact_info(person, contact); |
| |
435 |
| |
436 /* Add the contact to the manager. */ |
| |
437 purple_contact_manager_add(manager, contact); |
| |
438 |
| |
439 /* Make sure the contact is available. */ |
| |
440 contacts = purple_contact_manager_get_all(manager, account); |
| |
441 g_assert_nonnull(contacts); |
| |
442 |
| |
443 /* Make sure the contact and the person were added. */ |
| |
444 g_assert_cmpuint(g_list_model_get_n_items(contacts), ==, 1); |
| |
445 g_assert_cmpuint(g_list_model_get_n_items(model), ==, 1); |
| |
446 |
| |
447 /* Make sure the added signals were called. */ |
| |
448 g_assert_cmpint(contact_added_called, ==, 1); |
| |
449 g_assert_cmpint(person_added_called, ==, 1); |
| |
450 |
| |
451 /* Remove the person and the contacts. */ |
| |
452 purple_contact_manager_remove_person(manager, person, TRUE); |
| |
453 g_assert_cmpint(contact_removed_called, ==, 1); |
| |
454 g_assert_cmpint(person_removed_called, ==, 1); |
| |
455 |
| |
456 /* Make sure the person and contact were removed. */ |
| |
457 g_assert_cmpuint(g_list_model_get_n_items(model), ==, 0); |
| |
458 g_assert_cmpuint(g_list_model_get_n_items(contacts), ==, 0); |
| |
459 |
| |
460 /* Clean up.*/ |
| |
461 g_clear_object(&account); |
| |
462 g_clear_object(&contact); |
| |
463 g_clear_object(&person); |
| |
464 g_clear_object(&manager); |
| |
465 } |
| |
466 |
| 350 /****************************************************************************** |
467 /****************************************************************************** |
| 351 * Main |
468 * Main |
| 352 *****************************************************************************/ |
469 *****************************************************************************/ |
| 353 gint |
470 gint |
| 354 main(gint argc, gchar *argv[]) { |
471 main(gint argc, gchar *argv[]) { |