[tracker] libtracker-extract: Add and complete unit tests.



commit 3b625f076e48ba5a17a8a622801e280625158a7a
Author: Ivan Frade <ivan frade nokia com>
Date:   Thu Mar 18 21:53:18 2010 +0200

    libtracker-extract: Add and complete unit tests.

 tests/libtracker-extract/tracker-utils-test.c |   72 +++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtracker-extract/tracker-utils-test.c b/tests/libtracker-extract/tracker-utils-test.c
index d789c13..7270afe 100644
--- a/tests/libtracker-extract/tracker-utils-test.c
+++ b/tests/libtracker-extract/tracker-utils-test.c
@@ -57,6 +57,28 @@ test_guess_date (void)
 	g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
 	g_free (result);
 
+        result = tracker_date_guess ("2010");
+        g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-01-01T00:00:00Z"));
+        g_free (result);
+
+        result = tracker_date_guess ("A2010");
+        g_assert (!result);
+
+        /* Guessing from the code */
+        result = tracker_date_guess ("20100318010203-00:03Z");
+        g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03-00:03"));
+        g_free (result);
+
+        result = tracker_date_guess ("20100318010203+00:03Z");
+        g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03+00:03"));
+        g_free (result);
+
+        /* "YYYY-MM-DDThh:mm:ss.ff+zz:zz" */
+        result = tracker_date_guess ("2010-03-18T01:02:03.10-00:03");
+        g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03-00:03"));
+        g_free (result);
+
+
 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
 		result = tracker_date_guess (NULL);
 	}
@@ -64,6 +86,50 @@ test_guess_date (void)
 	g_test_trap_assert_failed ();
 }
 
+static void
+test_text_normalize ()
+{
+        gint i, n_words;
+        gchar *result;
+        struct {
+                gchar *input_text;
+                gchar *expected_output;
+                gint   n_words;
+        } TEST_BATTERY [] = {
+                { "this is the basic test", "this is the basic test", 5 },
+                { "         ", "", 0},
+                { "    A", "A", 1},
+                { "A   ", "A ", 1},
+                { "some.other:word-breaker/s", "some other word breaker s", 5},
+                { "or \"other\" symbols", "or other symbols", 3},
+                { "http://www.google.com";, "http www google com", 4},
+                { NULL, NULL, 0 }
+        };
+        
+        for (i = 0; TEST_BATTERY[i].input_text != NULL; i++) {
+                result = tracker_text_normalize (TEST_BATTERY[i].input_text, 10, &n_words);
+
+                g_assert_cmpstr (result, ==, TEST_BATTERY[i].expected_output);
+                g_assert_cmpint (n_words, ==, TEST_BATTERY[i].n_words);
+                g_free (result);
+        }
+}
+
+static void
+test_date_to_iso8601 ()
+{
+        /* Not much to test here because it uses strptime/strftime */
+        gchar *result;
+
+        result = tracker_date_format_to_iso8601 ("2010:03:13 12:12:12", "%Y:%m:%d %H:%M:%S");
+        g_assert (g_str_has_prefix (result, "2010-03-13T12:12:12"));
+        g_assert_cmpint (strlen (result), <=, 25);
+
+        /* Pattern and string don't match */
+        result = tracker_date_format_to_iso8601 ("2010:03:13 12:12", "%Y:%m:%d %H:%M:%S");
+        g_assert (result == NULL);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -75,6 +141,12 @@ main (int argc, char **argv)
 	g_test_add_func ("/libtracker-extract/tracker-utils/guess_date",
 	                 test_guess_date);
 
+        g_test_add_func ("/libtracker-extract/tracker-utils/text-normalize",
+                         test_text_normalize);
+
+        g_test_add_func ("/libtracker-extract/tracker-utils/date_to_iso8601",
+                         test_date_to_iso8601);
+
 	result = g_test_run ();
 
 	return result;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]