[tracker] test/libtracker-extract: Complete tests for tracker-utils
- From: Ivan Frade <ifrade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] test/libtracker-extract: Complete tests for tracker-utils
- Date: Mon, 17 Oct 2011 12:41:45 +0000 (UTC)
commit 7e23649e105d9f1472dfca43d02cd818df361b50
Author: Ivan Frade <ivan frade gmail com>
Date: Mon Oct 17 15:37:31 2011 +0300
test/libtracker-extract: Complete tests for tracker-utils
New tests for some functions, ignore deprecated functions in LCOV.
src/libtracker-extract/tracker-utils.c | 7 ++-
tests/libtracker-extract/Makefile.am | 3 +-
tests/libtracker-extract/getline-test.txt | 3 +
tests/libtracker-extract/tracker-test-utils.c | 63 +++++++++++++++++++++++-
4 files changed, 71 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-utils.c b/src/libtracker-extract/tracker-utils.c
index f7cb3ce..3fc202b 100644
--- a/src/libtracker-extract/tracker-utils.c
+++ b/src/libtracker-extract/tracker-utils.c
@@ -116,6 +116,7 @@ tracker_coalesce_strip (gint n_values,
return result;
}
+// LCOV_EXCL_START
/**
* tracker_coalesce:
* @n_values: the number of @Varargs supplied
@@ -162,7 +163,7 @@ tracker_coalesce (gint n_values,
return result;
}
-
+// LCOV_EXCL_STOP
/**
* tracker_merge_const:
@@ -218,6 +219,8 @@ tracker_merge_const (const gchar *delimiter,
return g_string_free (str, FALSE);
}
+// LCOV_EXCL_START
+
/**
* tracker_merge:
* @delimiter: the delimiter to use when merging
@@ -357,6 +360,8 @@ tracker_text_normalize (const gchar *text,
return g_string_free (string, FALSE);
}
+// LCOV_EXCL_STOP
+
/**
* tracker_text_validate_utf8:
* @text: the text to validate
diff --git a/tests/libtracker-extract/Makefile.am b/tests/libtracker-extract/Makefile.am
index 58385aa..375772e 100644
--- a/tests/libtracker-extract/Makefile.am
+++ b/tests/libtracker-extract/Makefile.am
@@ -54,4 +54,5 @@ EXTRA_DIST = encoding-detect.bin \
nb282393_simple.xmp \
exif-img.jpg \
exif-free-img.jpg \
- guarantee-mtime-test.txt
+ guarantee-mtime-test.txt \
+ getline-test.txt
diff --git a/tests/libtracker-extract/getline-test.txt b/tests/libtracker-extract/getline-test.txt
new file mode 100644
index 0000000..62d617f
--- /dev/null
+++ b/tests/libtracker-extract/getline-test.txt
@@ -0,0 +1,3 @@
+Line 1
+line 2
+line 3
diff --git a/tests/libtracker-extract/tracker-test-utils.c b/tests/libtracker-extract/tracker-test-utils.c
index cab8f7f..55e8dac 100644
--- a/tests/libtracker-extract/tracker-test-utils.c
+++ b/tests/libtracker-extract/tracker-test-utils.c
@@ -62,6 +62,9 @@ test_guess_date (void)
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-01-01T00:00:00Z"));
g_free (result);
+ result = tracker_date_guess ("201a");
+ g_assert (!result);
+
result = tracker_date_guess ("A2010");
g_assert (!result);
@@ -204,6 +207,57 @@ test_date_to_iso8601 ()
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
main (int argc, char **argv)
{
@@ -214,13 +268,16 @@ 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-validate-utf8",
test_text_validate_utf8);
-
g_test_add_func ("/libtracker-extract/tracker-utils/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 ();
return result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]