Commit 9baf7c35 authored by Philip Van Hoof's avatar Philip Van Hoof Committed by Martyn Russell

tests, libtracker-common: Add unit test for encoding guessing

parent 772f7b03
......@@ -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
ÊîñìîíàâòRadiotrance (Ðàäèîòðàíñ)Ê Çâ¸çäàì
\ No newline at end of file
......@@ -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 ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment