]> git.0d.be Git - empathy.git/blob - tests/check-helpers.c
fake the profile and the CM for tests
[empathy.git] / tests / check-helpers.c
1 /*
2  * check-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 "check-helpers.h"
24
25 static gboolean expecting_critical = FALSE;
26 static gboolean received_critical  = FALSE;
27
28 static void
29 check_helper_log_critical_func (const gchar *log_damain,
30                                 GLogLevelFlags log_level,
31                                 const gchar *message,
32                                 gpointer user_data)
33 {
34
35   if (!expecting_critical)
36     {
37       fail("Unexpected critical message: %s\n", message);
38     }
39
40   g_assert (log_level & G_LOG_LEVEL_CRITICAL);
41
42   received_critical = TRUE;
43 }
44
45 gboolean
46 got_critical (void)
47 {
48   return received_critical;
49 }
50
51 void
52 expect_critical (gboolean expected)
53 {
54   expecting_critical = expected;
55   received_critical = FALSE;
56 }
57
58 void
59 check_helpers_init (void)
60 {
61   g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL,
62       check_helper_log_critical_func, NULL);
63 }
64
65 gchar *
66 get_xml_file (const gchar *filename)
67 {
68   return g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "tests", "xml",
69       filename, NULL);
70 }
71
72 gchar *
73 get_user_xml_file (const gchar *filename)
74 {
75   return g_build_filename (g_get_tmp_dir (), filename, NULL);
76 }
77
78 void
79 copy_xml_file (const gchar *orig,
80                const gchar *dest)
81 {
82   gboolean result;
83   gchar *buffer;
84   gsize length;
85   gchar *sample;
86   gchar *file;
87
88   sample = get_xml_file (orig);
89   result = g_file_get_contents (sample, &buffer, &length, NULL);
90   fail_if (!result);
91
92   file = get_user_xml_file (dest);
93   result = g_file_set_contents (file, buffer, length, NULL);
94   fail_if (!result);
95
96   g_free (sample);
97   g_free (file);
98   g_free (buffer);
99 }