[tracker/version-macros: 8/9] tests, libtracker-common: Add unit test for encoding guessing
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/version-macros: 8/9] tests, libtracker-common: Add unit test for encoding guessing
- Date: Thu, 31 Mar 2011 19:31:04 +0000 (UTC)
commit 9baf7c35eba71364d1ee7e80118f03e78b3d99a0
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Mar 31 13:21:53 2011 +0200
tests, libtracker-common: Add unit test for encoding guessing
tests/libtracker-common/Makefile.am | 6 +-
tests/libtracker-common/encoding-detect.bin | 1 +
tests/libtracker-common/tracker-utils-test.c | 101 +++++++++++++++++---------
3 files changed, 73 insertions(+), 35 deletions(-)
---
diff --git a/tests/libtracker-common/Makefile.am b/tests/libtracker-common/Makefile.am
index 1083644..5d51148 100644
--- a/tests/libtracker-common/Makefile.am
+++ b/tests/libtracker-common/Makefile.am
@@ -8,7 +8,9 @@ TEST_PROGS += \
tracker-file-utils \
tracker-utils
-AM_CPPFLAGS = \
+AM_CPPFLAGS = \
+ -DTOP_SRCDIR=\"$(abs_top_srcdir)\" \
+ -DTOP_BUILDDIR=\"$(abs_top_builddir)\" \
$(BUILD_CFLAGS) \
-I$(top_srcdir)/src \
-I$(top_srcdir)/tests/common \
@@ -29,4 +31,4 @@ tracker_file_utils_SOURCES = tracker-file-utils-test.c
tracker_utils_SOURCES = tracker-utils-test.c
-EXTRA_DIST = non-utf8.txt
+EXTRA_DIST = non-utf8.txt encoding-detect.bin
diff --git a/tests/libtracker-common/encoding-detect.bin b/tests/libtracker-common/encoding-detect.bin
new file mode 100644
index 0000000..530d5a3
--- /dev/null
+++ b/tests/libtracker-common/encoding-detect.bin
@@ -0,0 +1 @@
+Ã?îñìîÃà âòRadiotrance (Ã?à äèîòðà Ãñ)Ã? Ã?â¸çäà ì
\ No newline at end of file
diff --git a/tests/libtracker-common/tracker-utils-test.c b/tests/libtracker-common/tracker-utils-test.c
index 08a3b5a..f1d5ae0 100644
--- a/tests/libtracker-common/tracker-utils-test.c
+++ b/tests/libtracker-common/tracker-utils-test.c
@@ -18,57 +18,89 @@
*
*/
+#include "config.h"
+
#include <glib-object.h>
#include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-encoding.h>
+
+static void
+test_encoding_guessing ()
+{
+ gchar *output;
+ GMappedFile *file = NULL;
+ gchar *prefix, *filen;
+
+ prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-common", NULL);
+ filen = g_build_filename (prefix, "encoding-detect.bin", NULL);
+
+ file = g_mapped_file_new (filen, FALSE, NULL);
+
+ output = tracker_encoding_guess (g_mapped_file_get_contents (file),
+ g_mapped_file_get_length (file));
+
+ g_assert_cmpstr (output, ==, "UTF-8");
+
+#if GLIB_CHECK_VERSION(2,22,0)
+ g_mapped_file_unref (file);
+#else
+ g_mapped_file_free (file);
+#endif
+
+ g_free (prefix);
+ g_free (filen);
+ g_free (output);
+}
+
static void
test_seconds_to_string ()
{
- gchar *result;
+ gchar *result;
- result = tracker_seconds_to_string (0, TRUE);
- g_assert_cmpstr (result, ==, "less than one second");
- g_free (result);
+ result = tracker_seconds_to_string (0, TRUE);
+ g_assert_cmpstr (result, ==, "less than one second");
+ g_free (result);
- result = tracker_seconds_to_string (0.1, TRUE);
- g_assert_cmpstr (result, ==, "less than one second");
- g_free (result);
+ result = tracker_seconds_to_string (0.1, TRUE);
+ g_assert_cmpstr (result, ==, "less than one second");
+ g_free (result);
- result = tracker_seconds_to_string (59.9, TRUE);
- g_assert_cmpstr (result, ==, "59s");
- g_free (result);
+ result = tracker_seconds_to_string (59.9, TRUE);
+ g_assert_cmpstr (result, ==, "59s");
+ g_free (result);
- result = tracker_seconds_to_string (60, TRUE);
- g_assert_cmpstr (result, ==, "01m");
- g_free (result);
+ result = tracker_seconds_to_string (60, TRUE);
+ g_assert_cmpstr (result, ==, "01m");
+ g_free (result);
- result = tracker_seconds_to_string (100.12, TRUE);
- g_assert_cmpstr (result, ==, "01m 40s");
- g_free (result);
+ result = tracker_seconds_to_string (100.12, TRUE);
+ g_assert_cmpstr (result, ==, "01m 40s");
+ g_free (result);
- result = tracker_seconds_to_string (100, FALSE);
- g_assert_cmpstr (result, ==, "01 minute 40 seconds");
- g_free (result);
+ result = tracker_seconds_to_string (100, FALSE);
+ g_assert_cmpstr (result, ==, "01 minute 40 seconds");
+ g_free (result);
- result = tracker_seconds_to_string (1000000, TRUE);
- g_assert_cmpstr (result, ==, "11d 13h 46m 40s");
- g_free (result);
+ result = tracker_seconds_to_string (1000000, TRUE);
+ g_assert_cmpstr (result, ==, "11d 13h 46m 40s");
+ g_free (result);
- result = tracker_seconds_to_string (1000000000, TRUE);
- g_assert_cmpstr (result, ==, "11574d 01h 46m 40s");
- g_free (result);
+ result = tracker_seconds_to_string (1000000000, TRUE);
+ g_assert_cmpstr (result, ==, "11574d 01h 46m 40s");
+ g_free (result);
}
static void
test_seconds_estimate_to_string ()
{
- gchar *result;
+ gchar *result;
- result = tracker_seconds_estimate_to_string (60, TRUE, 60, 120);
- g_assert_cmpstr (result, ==, "02m");
- g_free (result);
- g_print ("%s\n", result);
+ result = tracker_seconds_estimate_to_string (60, TRUE, 60, 120);
+ g_assert_cmpstr (result, ==, "02m");
+ g_free (result);
+ g_print ("%s\n", result);
}
int
@@ -77,11 +109,14 @@ main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/libtracker-extract/tracker-utils/seconds_to_string",
+ g_test_add_func ("/libtracker-common/tracker-utils/seconds_to_string",
test_seconds_to_string);
- g_test_add_func ("/libtracker-extract/tracker-utils/seconds_estimate_to_string",
+ g_test_add_func ("/libtracker-common/tracker-utils/seconds_estimate_to_string",
test_seconds_estimate_to_string);
- return g_test_run ();
+ g_test_add_func ("/libtracker-common/tracker-encoding/encoding_guessing",
+ test_encoding_guessing);
+
+ return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]