2 * check-helpers.c - Source for some check helpers
3 * Copyright (C) 2007-2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <glib/gstdio.h>
24 #include <gconf/gconf.h>
25 #include <gconf/gconf-client.h>
27 #include "check-helpers.h"
29 static gboolean expecting_critical = FALSE;
30 static gboolean received_critical = FALSE;
33 check_helper_log_critical_func (const gchar *log_damain,
34 GLogLevelFlags log_level,
39 if (!expecting_critical)
41 fail("Unexpected critical message: %s\n", message);
44 g_assert (log_level & G_LOG_LEVEL_CRITICAL);
46 received_critical = TRUE;
52 return received_critical;
56 expect_critical (gboolean expected)
58 expecting_critical = expected;
59 received_critical = FALSE;
63 check_helpers_init (void)
65 g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL,
66 check_helper_log_critical_func, NULL);
70 get_xml_file (const gchar *filename)
72 return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
77 get_user_xml_file (const gchar *filename)
79 return g_build_filename (g_get_tmp_dir (), filename, NULL);
83 copy_xml_file (const gchar *orig,
92 sample = get_xml_file (orig);
93 result = g_file_get_contents (sample, &buffer, &length, NULL);
96 file = get_user_xml_file (dest);
97 result = g_file_set_contents (file, buffer, length, NULL);
106 remove_account_from_gconf (McAccount *account)
110 GError *error = NULL;
111 GSList *entries = NULL, *l;
113 client = gconf_client_get_default ();
114 path = g_strdup_printf ("/apps/telepathy/mc/accounts/%s",
115 mc_account_get_unique_name (account));
117 entries = gconf_client_all_entries (client, path, &error);
120 g_print ("failed to list entries in %s: %s\n", path, error->message);
121 g_error_free (error);
125 for (l = entries; l != NULL; l = g_slist_next (l))
127 GConfEntry *entry = l->data;
129 if (g_str_has_suffix (entry->key, "data_dir"))
133 dir = gconf_client_get_string (client, entry->key, &error);
136 g_print ("get data_dir string failed: %s\n", entry->key);
137 g_error_free (error);
142 if (g_rmdir (dir) != 0)
143 g_print ("can't remove %s\n", dir);
147 /* FIXME: this doesn't remove the key */
148 gconf_client_unset (client, entry->key, &error);
151 g_print ("unset of %s failed: %s\n", path, error->message);
152 g_error_free (error);
156 gconf_entry_free (entry);
159 g_slist_free (entries);
161 g_object_unref (client);