gboolean add_contact_from_test_case_verify (EBookClient *book_client, const gchar *case_name, EContact **contact) { gchar *vcard; EContact *contact_orig; EContact *contact_final; gchar *uid; GError *error = NULL; vcard = new_vcard_from_test_case (case_name); contact_orig = e_contact_new_from_vcard (vcard); g_free (vcard); if (!e_book_client_add_contact_sync (book_client, contact_orig, &uid, NULL, &error)) g_error ("add contact sync: %s", error->message); e_contact_set (contact_orig, E_CONTACT_UID, uid); if (!e_book_client_get_contact_sync (book_client, uid, &contact_final, NULL, &error)) g_error ("get contact sync: %s", error->message); /* verify the contact was added "successfully" (not thorough) */ g_assert (contacts_are_equal_shallow (contact_orig, contact_final)); if (contact) *contact = contact_final; else g_object_unref (contact_final); g_object_unref (contact_orig); g_free (uid); return TRUE; }
gint main (gint argc, gchar **argv) { EBookClient *book_client; GError *error = NULL; EContact *contact; gchar *vcard; main_initialize (); /* * Setup */ book_client = new_temp_client (NULL); g_return_val_if_fail (book_client != NULL, 1); if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) { report_error ("client open sync", &error); g_object_unref (book_client); return 1; } /* * Sync version */ if (!add_contact_from_test_case_verify (book_client, "simple-1", &contact)) { g_object_unref (book_client); return 1; } g_object_unref (contact); if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) { report_error ("client remove sync", &error); g_object_unref (book_client); return 1; } g_object_unref (book_client); /* * Async version */ book_client = new_temp_client (NULL); g_return_val_if_fail (book_client != NULL, 1); if (!e_client_open_sync (E_CLIENT (book_client), FALSE, NULL, &error)) { report_error ("client open sync", &error); g_object_unref (book_client); return 1; } vcard = new_vcard_from_test_case ("simple-1"); contact = e_contact_new_from_vcard (vcard); g_free (vcard); e_book_client_add_contact (book_client, contact, NULL, add_contact_cb, NULL); g_object_unref (contact); start_main_loop (NULL, NULL); if (!e_client_remove_sync (E_CLIENT (book_client), NULL, &error)) { report_error ("client remove sync", &error); g_object_unref (book_client); return 1; } g_object_unref (book_client); return get_main_loop_stop_result (); }