1 /*
2  * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
3  *
4  * This program 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 program 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 program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  *
19  */
20 
21 #include "config-miners.h"
22 
23 #include <glib-object.h>
24 #include <libtracker-extract/tracker-encoding.h>
25 #include <libtracker-miners-common/tracker-locale.h>
26 #include <locale.h>
27 
28 static void
test_encoding_guessing()29 test_encoding_guessing ()
30 {
31 	gchar *output;
32 	GMappedFile *file = NULL;
33 	gchar *prefix, *filen;
34 
35 	prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-extract", NULL);
36 	filen = g_build_filename (prefix, "encoding-detect.bin", NULL);
37 
38 	file = g_mapped_file_new (filen, FALSE, NULL);
39 
40 	output = tracker_encoding_guess (g_mapped_file_get_contents (file),
41 	                                 g_mapped_file_get_length (file),
42 	                                 NULL);
43 
44 	g_assert_cmpstr (output, ==, "UTF-8");
45 
46 	g_mapped_file_unref (file);
47 
48 	g_free (prefix);
49 	g_free (filen);
50 	g_free (output);
51 }
52 
53 static void
test_encoding_can_guess(void)54 test_encoding_can_guess (void)
55 {
56         /* This just duplicates the function code... */
57 #if defined (HAVE_ENCA) || defined (HAVE_LIBICU_CHARSET_DETECTION)
58         g_assert (tracker_encoding_can_guess ());
59 #else
60         g_assert (!tracker_encoding_can_guess ());
61 #endif
62 }
63 
64 int
main(int argc,char ** argv)65 main (int argc, char **argv)
66 {
67 	g_test_init (&argc, &argv, NULL);
68 
69 	setlocale (LC_ALL, "");
70 	g_test_add_func ("/libtracker-extract/tracker-encoding/encoding_guessing",
71 	                 test_encoding_guessing);
72 	g_test_add_func ("/libtracker-extract/tracker-encoding/can_guess",
73 	                 test_encoding_can_guess);
74 
75 	return g_test_run ();
76 }
77