ESourceRegistry: Do not mandate builtin sources.
[platform/upstream/evolution-data-server.git] / tests / libebook / client / client-test-utils.c
index 4fb45d7..bb41e82 100644 (file)
@@ -1,4 +1,26 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2011, 2012 Red Hat, Inc. (www.redhat.com)
+ * Copyright (C) 2012 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Milan Crha <mcrha@redhat.com>
+ *          Matthew Barnes <mbarnes@redhat.com>
+ *          Tristan Van Berkom <tristanvb@openismus.com>
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -49,6 +71,7 @@ open_system_book (ESourceRegistry *registry,
        main_initialize ();
 
        source = e_source_registry_ref_builtin_address_book (registry);
+       g_return_val_if_fail (source != NULL, NULL);
        book_client = e_book_client_new (source, &error);
        g_object_unref (source);
 
@@ -95,14 +118,10 @@ idle_cb (gpointer data)
        g_return_val_if_fail (idle->func != NULL, FALSE);
 
        if (idle->run_in_thread) {
-               GError *error = NULL;
-
-               g_thread_create (idle->func, idle->data, FALSE, &error);
+               GThread *thread;
 
-               if (error) {
-                       report_error ("create thread", &error);
-                       stop_main_loop (1);
-               }
+               thread = g_thread_new (NULL, idle->func, idle->data);
+               g_thread_unref (thread);
        } else {
                idle->func (idle->data);
        }
@@ -288,8 +307,6 @@ foreach_configured_source_async_next (gpointer *foreach_async_data,
        return FALSE;
 }
 
-
-
 typedef struct {
        GMainLoop       *loop;
        const gchar     *uid;
@@ -319,7 +336,7 @@ create_book_idle (CreateBookData *data)
        if (!data->book)
                g_error ("Unable to create the book: %s", error->message);
 
-       g_idle_add ((GSourceFunc)quit_idle, data);
+       g_idle_add ((GSourceFunc) quit_idle, data);
 
        return FALSE;
 }
@@ -347,7 +364,7 @@ register_source_idle (CreateBookData *data)
        /* XXX e_source_registry_commit_source_sync isnt really sync... or else
         * we could call e_source_registry_ref_source() immediately
         */
-       g_timeout_add (20, (GSourceFunc)create_book_idle, data);
+       g_timeout_add (20, (GSourceFunc) create_book_idle, data);
 
        return FALSE;
 }
@@ -360,7 +377,7 @@ ebook_test_utils_book_with_uid (const gchar *uid)
        data.uid = uid;
 
        data.loop = g_main_loop_new (NULL, FALSE);
-       g_idle_add ((GSourceFunc)register_source_idle, &data);
+       g_idle_add ((GSourceFunc) register_source_idle, &data);
        g_main_loop_run (data.loop);
        g_main_loop_unref (data.loop);
 
@@ -402,7 +419,8 @@ new_vcard_from_test_case (const gchar *case_name)
        filename = g_build_filename (SRCDIR, "..", "data", "vcards", case_filename, NULL);
        file = g_file_new_for_path (filename);
        if (!g_file_load_contents (file, NULL, &vcard, NULL, NULL, &error)) {
-               g_warning ("failed to read test contact file '%s': %s",
+               g_warning (
+                       "failed to read test contact file '%s': %s",
                                filename, error->message);
                exit (1);
        }