tracker-0.16.2/tests/common/tracker-test-helpers.c

No issues found

 1 /*
 2  * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
 3  *
 4  * This library is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU General Public
 6  * License as published by the Free Software Foundation; either
 7  * version 2 of the License, or (at your option) any later version.
 8  *
 9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19 #include "tracker-test-helpers.h"
20 
21 static gchar *nonutf8_str = NULL;
22 
23 const gchar *
24 tracker_test_helpers_get_nonutf8 (void)
25 {
26 	GMappedFile *file = NULL;
27 
28 	if (!nonutf8_str) {
29 		file = g_mapped_file_new (TEST_TEXT, FALSE, NULL);
30 		nonutf8_str = g_strdup (g_mapped_file_get_contents (file));
31 		nonutf8_str [g_mapped_file_get_length (file) -1] = '\0';
32 #if GLIB_CHECK_VERSION(2,22,0)
33 		g_mapped_file_unref (file);
34 #else
35 		g_mapped_file_free (file);
36 #endif
37 	}
38 
39 	return nonutf8_str;
40 }
41 
42 void
43 tracker_test_helpers_free_nonutf8 (void)
44 {
45 	if (nonutf8_str) {
46 		g_free (nonutf8_str);
47 		nonutf8_str = NULL;
48 	}
49 }