Improving test-client-remove-contact
authorTristan Van Berkom <tristanvb@openismus.com>
Mon, 21 Jan 2013 08:35:13 +0000 (17:35 +0900)
committerTristan Van Berkom <tristanvb@openismus.com>
Wed, 23 Jan 2013 04:38:13 +0000 (13:38 +0900)
Check for error type is more clear and safe now.

tests/libebook/client/test-client-remove-contact.c

index 2649f09..bb314aa 100644 (file)
@@ -8,12 +8,28 @@
 static ETestServerClosure book_closure = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 
 static void
+check_removed_contact (EBookClient *book_client,
+                      const gchar *uid)
+{
+       GError *error = NULL;
+       EContact *contact = NULL;
+
+       if (e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error))
+               g_error ("succeeded to fetch removed contact");
+       else if (!g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND))
+               g_error ("Wrong error in get contact sync on removed contact: %s (domain: %s, code: %d)",
+                        error->message, g_quark_to_string (error->domain), error->code);
+       else
+               g_clear_error (&error);
+}
+
+static void
 test_remove_contact_sync (ETestServerFixture *fixture,
                           gconstpointer user_data)
 {
        EBookClient *book_client;
        GError *error = NULL;
-       EContact *contact;
+       EContact *contact = NULL;
        gchar *uid;
 
        book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
@@ -28,11 +44,7 @@ test_remove_contact_sync (ETestServerFixture *fixture,
 
        g_object_unref (contact);
 
-       if (!e_book_client_get_contact_sync (book_client, uid, &contact, NULL, &error) &&
-           g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
-               g_clear_error (&error);
-       } else
-               g_error ("fail with get contact sync on removed contact: %s", error->message);
+       check_removed_contact (book_client, uid);
 
        g_free (uid);
 }
@@ -49,16 +61,11 @@ remove_contact_cb (GObject *source_object,
 {
        RemoveData *data = (RemoveData *) user_data;
        GError *error = NULL;
-       EContact *contact = NULL;
 
        if (!e_book_client_remove_contact_finish (E_BOOK_CLIENT (source_object), result, &error))
                g_error ("remove contact finish: %s", error->message);
 
-       if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), data->uid, &contact, NULL, &error) &&
-           g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) {
-               g_clear_error (&error);
-       } else
-               g_error ("fail with get contact on removed contact: %s", error->message);
+       check_removed_contact (E_BOOK_CLIENT (source_object), data->uid);
 
        g_main_loop_quit (data->loop);
 }