Commit 7e23649e authored by Ivan Frade's avatar Ivan Frade

test/libtracker-extract: Complete tests for tracker-utils

New tests for some functions, ignore deprecated functions in LCOV.
parent 72496353
...@@ -116,6 +116,7 @@ tracker_coalesce_strip (gint n_values, ...@@ -116,6 +116,7 @@ tracker_coalesce_strip (gint n_values,
return result; return result;
} }
// LCOV_EXCL_START
/** /**
* tracker_coalesce: * tracker_coalesce:
* @n_values: the number of @Varargs supplied * @n_values: the number of @Varargs supplied
...@@ -162,7 +163,7 @@ tracker_coalesce (gint n_values, ...@@ -162,7 +163,7 @@ tracker_coalesce (gint n_values,
return result; return result;
} }
// LCOV_EXCL_STOP
/** /**
* tracker_merge_const: * tracker_merge_const:
...@@ -218,6 +219,8 @@ tracker_merge_const (const gchar *delimiter, ...@@ -218,6 +219,8 @@ tracker_merge_const (const gchar *delimiter,
return g_string_free (str, FALSE); return g_string_free (str, FALSE);
} }
// LCOV_EXCL_START
/** /**
* tracker_merge: * tracker_merge:
* @delimiter: the delimiter to use when merging * @delimiter: the delimiter to use when merging
...@@ -357,6 +360,8 @@ tracker_text_normalize (const gchar *text, ...@@ -357,6 +360,8 @@ tracker_text_normalize (const gchar *text,
return g_string_free (string, FALSE); return g_string_free (string, FALSE);
} }
// LCOV_EXCL_STOP
/** /**
* tracker_text_validate_utf8: * tracker_text_validate_utf8:
* @text: the text to validate * @text: the text to validate
......
...@@ -54,4 +54,5 @@ EXTRA_DIST = encoding-detect.bin \ ...@@ -54,4 +54,5 @@ EXTRA_DIST = encoding-detect.bin \
nb282393_simple.xmp \ nb282393_simple.xmp \
exif-img.jpg \ exif-img.jpg \
exif-free-img.jpg \ exif-free-img.jpg \
guarantee-mtime-test.txt guarantee-mtime-test.txt \
getline-test.txt
...@@ -62,6 +62,9 @@ test_guess_date (void) ...@@ -62,6 +62,9 @@ test_guess_date (void)
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-01-01T00:00:00Z")); g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-01-01T00:00:00Z"));
g_free (result); g_free (result);
result = tracker_date_guess ("201a");
g_assert (!result);
result = tracker_date_guess ("A2010"); result = tracker_date_guess ("A2010");
g_assert (!result); g_assert (!result);
...@@ -204,6 +207,57 @@ test_date_to_iso8601 () ...@@ -204,6 +207,57 @@ test_date_to_iso8601 ()
g_assert (result == NULL); g_assert (result == NULL);
} }
static void
test_coalesce_strip ()
{
/* Used in other tests, but this one can try some corner cases */
g_assert (!tracker_coalesce_strip (0, NULL));
g_assert_cmpstr (tracker_coalesce_strip (2, "", "a", NULL), ==, "a");
}
static void
test_merge_const ()
{
gchar *result;
result = tracker_merge_const ("*", 3, "a", "b", NULL);
g_assert_cmpstr (result, ==, "a*b");
g_free (result);
result = tracker_merge_const ("****", 3, "a", "b", NULL);
g_assert_cmpstr (result, ==, "a****b");
g_free (result);
result = tracker_merge_const (NULL, 3, "a", "b", NULL);
g_assert_cmpstr (result, ==, "ab");
g_free (result);
result = tracker_merge_const ("", 3, "a", "b", NULL);
g_assert_cmpstr (result, ==, "ab");
g_free (result);
result = tracker_merge_const ("*", 0, NULL);
g_assert (!result);
}
void
test_getline ()
{
FILE *f;
gchar *line = NULL;
gsize n;
f = fopen ("./getline-test.txt", "r");
g_assert_cmpint (tracker_getline (&line, &n, f), >, 0);
g_assert_cmpstr (line, ==, "Line 1\n");
g_assert_cmpint (tracker_getline (&line, &n, f), >, 0);
g_assert_cmpstr (line, ==, "line 2\n");
g_assert_cmpint (tracker_getline (&line, &n, f), >, 0);
g_assert_cmpstr (line, ==, "line 3\n");
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
...@@ -214,13 +268,16 @@ main (int argc, char **argv) ...@@ -214,13 +268,16 @@ main (int argc, char **argv)
g_test_add_func ("/libtracker-extract/tracker-utils/guess_date", g_test_add_func ("/libtracker-extract/tracker-utils/guess_date",
test_guess_date); test_guess_date);
g_test_add_func ("/libtracker-extract/tracker-utils/text-validate-utf8", g_test_add_func ("/libtracker-extract/tracker-utils/text-validate-utf8",
test_text_validate_utf8); test_text_validate_utf8);
g_test_add_func ("/libtracker-extract/tracker-utils/date_to_iso8601", g_test_add_func ("/libtracker-extract/tracker-utils/date_to_iso8601",
test_date_to_iso8601); test_date_to_iso8601);
g_test_add_func ("/libtracker-extract/tracker-utils/coalesce_strip",
test_coalesce_strip);
g_test_add_func ("/libtracker-extract/tracker-utils/merge_const",
test_merge_const);
g_test_add_func ("/libtracker-extract/tracker-utils/getline",
test_getline);
result = g_test_run (); result = g_test_run ();
return result; return result;
......
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