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