]> git.0d.be Git - empathy.git/blob - tests/test-helper.c
8d7be5f4a0c120cc1c4e73435c3bd56d74fdaf2c
[empathy.git] / tests / test-helper.c
1 /*
2  * test-helper.c - Source for some test helper functions
3  * Copyright (C) 2007-2009 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 "config.h"
21 #include "test-helper.h"
22
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <glib-object.h>
26 #include <gtk/gtk.h>
27
28 #include "empathy-ui-utils.h"
29
30 void
31 test_init (int argc,
32     char **argv)
33 {
34   g_test_init (&argc, &argv, NULL);
35   gtk_init (&argc, &argv);
36   empathy_gtk_init ();
37 }
38
39 void
40 test_deinit (void)
41 {
42   ;
43 }
44
45 gchar *
46 get_xml_file (const gchar *filename)
47 {
48   return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
49       filename, NULL);
50 }
51
52 gchar *
53 get_user_xml_file (const gchar *filename)
54 {
55   return g_build_filename (g_get_tmp_dir (), filename, NULL);
56 }
57
58 void
59 copy_xml_file (const gchar *orig,
60                const gchar *dest)
61 {
62   gboolean result;
63   gchar *buffer;
64   gsize length;
65   gchar *sample;
66   gchar *file;
67
68   sample = get_xml_file (orig);
69   result = g_file_get_contents (sample, &buffer, &length, NULL);
70   g_assert (result);
71
72   file = get_user_xml_file (dest);
73   result = g_file_set_contents (file, buffer, length, NULL);
74   g_assert (result);
75
76   g_free (sample);
77   g_free (file);
78   g_free (buffer);
79 }
80