2 * test-helper.c - Source for some test helper functions
3 * Copyright (C) 2007-2009 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
22 #include <glib-object.h>
24 #include "test-helper.h"
30 g_test_init (&argc, &argv, NULL);
41 get_xml_file (const gchar *filename)
43 return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
48 get_user_xml_file (const gchar *filename)
50 return g_build_filename (g_get_tmp_dir (), filename, NULL);
54 copy_xml_file (const gchar *orig,
63 sample = get_xml_file (orig);
64 result = g_file_get_contents (sample, &buffer, &length, NULL);
67 file = get_user_xml_file (dest);
68 result = g_file_set_contents (file, buffer, length, NULL);
78 get_test_account (void)
81 EmpathyAccountManager *account_manager;
82 EmpathyAccount *account;
85 account_manager = empathy_account_manager_dup_singleton ();
86 profile = mc_profile_lookup ("test");
87 accounts = mc_accounts_list_by_profile (profile);
88 if (g_list_length (accounts) == 0)
90 /* need to create a test account */
91 account = empathy_account_manager_create_by_profile (account_manager,
96 /* reuse an existing test account */
97 McAccount *mc_account;
98 mc_account = accounts->data;
99 account = empathy_account_manager_lookup (account_manager,
100 mc_account_get_unique_name (mc_account));
102 g_object_unref (account_manager);
104 g_object_unref (profile);
109 /* Not used for now as there is no API to remove completely gconf keys.
110 * So we reuse existing accounts instead of creating new ones */
112 destroy_test_account (EmpathyAccount *account)
116 GError *error = NULL;
117 GSList *entries = NULL, *l;
118 EmpathyAccountManager *manager;
120 client = gconf_client_get_default ();
121 path = g_strdup_printf ("/apps/telepathy/mc/accounts/%s",
122 empathy_account_get_unique_name (account));
124 entries = gconf_client_all_entries (client, path, &error);
127 g_print ("failed to list entries in %s: %s\n", path, error->message);
128 g_error_free (error);
132 for (l = entries; l != NULL; l = g_slist_next (l))
134 GConfEntry *entry = l->data;
136 if (g_str_has_suffix (entry->key, "data_dir"))
140 dir = gconf_client_get_string (client, entry->key, &error);
143 g_print ("get data_dir string failed: %s\n", entry->key);
144 g_error_free (error);
149 if (g_rmdir (dir) != 0)
150 g_print ("can't remove %s\n", dir);
156 /* FIXME: this doesn't remove the key */
157 gconf_client_unset (client, entry->key, &error);
160 g_print ("unset of %s failed: %s\n", path, error->message);
161 g_error_free (error);
165 gconf_entry_unref (entry);
168 g_slist_free (entries);
170 g_object_unref (client);
173 manager = empathy_account_manager_dup_singleton ();
174 empathy_account_manager_remove (manager, account);
175 g_object_unref (account);
176 g_object_unref (manager);