]> git.0d.be Git - empathy.git/blob - tests/check-empathy-helpers.c
Updated Kannada(kn) translation
[empathy.git] / tests / check-empathy-helpers.c
1 /*
2  * check-empathy-helpers.c - Source for some check helpers
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include <glib/gstdio.h>
24 #include <gconf/gconf.h>
25 #include <gconf/gconf-client.h>
26
27 #include <libempathy/empathy-account-manager.h>
28
29 #include "check-helpers.h"
30 #include "check-empathy-helpers.h"
31
32 gchar *
33 get_xml_file (const gchar *filename)
34 {
35   return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
36       filename, NULL);
37 }
38
39 gchar *
40 get_user_xml_file (const gchar *filename)
41 {
42   return g_build_filename (g_get_tmp_dir (), filename, NULL);
43 }
44
45 void
46 copy_xml_file (const gchar *orig,
47                const gchar *dest)
48 {
49   gboolean result;
50   gchar *buffer;
51   gsize length;
52   gchar *sample;
53   gchar *file;
54
55   sample = get_xml_file (orig);
56   result = g_file_get_contents (sample, &buffer, &length, NULL);
57   fail_if (!result);
58
59   file = get_user_xml_file (dest);
60   result = g_file_set_contents (file, buffer, length, NULL);
61   fail_if (!result);
62
63   g_free (sample);
64   g_free (file);
65   g_free (buffer);
66 }
67
68 #if 0
69 EmpathyAccount *
70 get_test_account (void)
71 {
72   McProfile *profile;
73   EmpathyAccountManager *account_manager;
74   EmpathyAccount *account;
75   GList *accounts;
76
77   account_manager = empathy_account_manager_dup_singleton ();
78   profile = mc_profile_lookup ("test");
79   accounts = mc_accounts_list_by_profile (profile);
80   if (g_list_length (accounts) == 0)
81     {
82       /* need to create a test account */
83       account = empathy_account_manager_create_by_profile (account_manager,
84           profile);
85     }
86   else
87     {
88       /* reuse an existing test account */
89       McAccount *mc_account;
90       mc_account = accounts->data;
91       account = empathy_account_manager_lookup (account_manager,
92         mc_account_get_unique_name (mc_account));
93     }
94   g_object_unref (account_manager);
95
96   g_object_unref (profile);
97
98   return account;
99 }
100
101 /* Not used for now as there is no API to remove completely gconf keys.
102  * So we reuse existing accounts instead of creating new ones */
103 void
104 destroy_test_account (EmpathyAccount *account)
105 {
106   GConfClient *client;
107   gchar *path;
108   GError *error = NULL;
109   GSList *entries = NULL, *l;
110   EmpathyAccountManager *manager;
111
112   client = gconf_client_get_default ();
113   path = g_strdup_printf ("/apps/telepathy/mc/accounts/%s",
114       empathy_account_get_unique_name (account));
115
116   entries = gconf_client_all_entries (client, path, &error);
117   if (error != NULL)
118     {
119       g_print ("failed to list entries in %s: %s\n", path, error->message);
120       g_error_free (error);
121       error = NULL;
122     }
123
124   for (l = entries; l != NULL; l = g_slist_next (l))
125     {
126       GConfEntry *entry = l->data;
127
128       if (g_str_has_suffix (entry->key, "data_dir"))
129         {
130           gchar *dir;
131
132           dir = gconf_client_get_string (client, entry->key, &error);
133           if (error != NULL)
134             {
135               g_print ("get data_dir string failed: %s\n", entry->key);
136               g_error_free (error);
137               error = NULL;
138             }
139           else
140             {
141               if (g_rmdir (dir) != 0)
142                 g_print ("can't remove %s\n", dir);
143             }
144
145           g_free (dir);
146         }
147
148       /* FIXME: this doesn't remove the key */
149       gconf_client_unset (client, entry->key, &error);
150       if (error != NULL)
151         {
152           g_print ("unset of %s failed: %s\n", path, error->message);
153           g_error_free (error);
154           error = NULL;
155         }
156
157       gconf_entry_unref (entry);
158     }
159
160   g_slist_free (entries);
161
162   g_object_unref (client);
163   g_free (path);
164
165   manager = empathy_account_manager_dup_singleton ();
166   empathy_account_manager_remove (manager, account);
167   g_object_unref (account);
168   g_object_unref (manager);
169 }
170 #endif