No issues found
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.h"
22
23 #include <glib-object.h>
24 #include <libtracker-extract/tracker-encoding.h>
25 #include <libtracker-common/tracker-locale.h>
26
27 static void
28 test_encoding_guessing ()
29 {
30 gchar *output;
31 GMappedFile *file = NULL;
32 gchar *prefix, *filen;
33
34 prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-extract", NULL);
35 filen = g_build_filename (prefix, "encoding-detect.bin", NULL);
36
37 file = g_mapped_file_new (filen, FALSE, NULL);
38
39 output = tracker_encoding_guess (g_mapped_file_get_contents (file),
40 g_mapped_file_get_length (file));
41
42 g_assert_cmpstr (output, ==, "UTF-8");
43
44 #if GLIB_CHECK_VERSION(2,22,0)
45 g_mapped_file_unref (file);
46 #else
47 g_mapped_file_free (file);
48 #endif
49
50 g_free (prefix);
51 g_free (filen);
52 g_free (output);
53 }
54
55 static void
56 test_encoding_can_guess (void)
57 {
58 /* This just duplicates the function code... */
59 #if defined (HAVE_ENCA) || defined (HAVE_MEEGOTOUCH)
60 g_assert (tracker_encoding_can_guess ());
61 #else
62 g_assert (!tracker_encoding_can_guess ());
63 #endif
64 }
65
66 int
67 main (int argc, char **argv)
68 {
69 g_test_init (&argc, &argv, NULL);
70
71 tracker_locale_init ();
72 g_test_add_func ("/libtracker-extract/tracker-encoding/encoding_guessing",
73 test_encoding_guessing);
74 g_test_add_func ("/libtracker-extract/tracker-encoding/can_guess",
75 test_encoding_can_guess);
76 tracker_locale_shutdown ();
77
78 return g_test_run ();
79 }