[tracker] libtracker-common: complete tracker-type-utils unit tests



commit 14282007df0218e001ea8c6903e0ab095e08ea1a
Author: Ivan Frade <ivan frade nokia com>
Date:   Mon Mar 22 21:15:14 2010 +0200

    libtracker-common: complete tracker-type-utils unit tests

 tests/libtracker-common/tracker-type-utils-test.c |  128 +++++++++++++++++++++
 1 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c
index f143e89..019c618 100644
--- a/tests/libtracker-common/tracker-type-utils-test.c
+++ b/tests/libtracker-common/tracker-type-utils-test.c
@@ -248,6 +248,26 @@ test_string_in_string_list (void)
 }
 
 static void
+test_string_in_gslist (void)
+{
+        GSList *input = NULL;
+
+        input = g_slist_prepend (input, g_strdup ("one"));
+        input = g_slist_prepend (input, g_strdup ("two"));
+        input = g_slist_prepend (input, g_strdup ("three"));
+        input = g_slist_prepend (input, g_strdup ("four"));
+
+        g_assert (tracker_string_in_gslist ("one", input));
+        g_assert (tracker_string_in_gslist ("two", input));
+        g_assert (tracker_string_in_gslist ("three", input));
+        g_assert (tracker_string_in_gslist ("four", input));
+        g_assert (!tracker_string_in_gslist ("five", input));
+
+        g_slist_foreach (input, (GFunc)g_free, NULL);
+        g_slist_free (input);
+}
+
+static void
 test_gslist_to_string_list (void)
 {
 	GSList *input = NULL;
@@ -275,6 +295,36 @@ test_gslist_to_string_list (void)
 }
 
 static void
+test_string_list_to_gslist (void)
+{
+        const gchar  *input [] = {"one", "two", "three", "four", NULL};
+        GSList *result = NULL;
+
+        result = tracker_string_list_to_gslist ((gchar **)input, -1);
+        g_assert (result);
+        g_assert_cmpint (g_slist_length (result), ==, 4);
+
+        /* This function is tested in other test, so it should work or fail there also */
+        g_assert (tracker_string_in_gslist ("one", result));
+        g_assert (tracker_string_in_gslist ("two", result));
+        g_assert (tracker_string_in_gslist ("three", result));
+        g_assert (tracker_string_in_gslist ("four", result));
+
+        g_slist_foreach (result, (GFunc)g_free, NULL);
+        g_slist_free (result);
+
+        result = tracker_string_list_to_gslist ((gchar **)input, 2);
+        g_assert (result);
+        g_assert_cmpint (g_slist_length (result), ==, 2);
+
+        g_assert (tracker_string_in_gslist ("one", result));
+        g_assert (tracker_string_in_gslist ("two", result));
+        g_assert (!tracker_string_in_gslist ("three", result));
+        g_assert (!tracker_string_in_gslist ("four", result));
+
+}
+
+static void
 test_string_list_to_string (void)
 {
 	const gchar *input = "one two three four";
@@ -308,6 +358,17 @@ test_string_list_to_string (void)
 	g_strfreev (pieces);
 }
 
+static void 
+test_string_to_string_list (void)
+{
+        const gchar *input = "first line";
+        gchar **result;
+
+        result = tracker_string_to_string_list (input);
+        g_assert_cmpint (g_strv_length (result), ==, 1);
+        g_assert_cmpstr (result [0], ==, "first line");
+}
+
 static void
 test_boolean_as_text_to_number (void)
 {
@@ -360,6 +421,63 @@ test_boolean_as_text_to_number (void)
 	g_test_trap_assert_failed ();
 }
 
+static void
+test_gslist_with_string_data_equal (void)
+{
+        GSList *list1 = NULL;
+        GSList *list2 = NULL;
+        GSList *shorty = NULL;
+        GSList *list3 = NULL;
+
+        list1 = g_slist_prepend (list1, g_strdup ("one"));
+        list1 = g_slist_prepend (list1, g_strdup ("two"));
+        list1 = g_slist_prepend (list1, g_strdup ("three"));
+
+        g_assert (tracker_gslist_with_string_data_equal (list1, list1));
+
+        shorty = g_slist_prepend (shorty, g_strdup ("one"));
+        g_assert (!tracker_gslist_with_string_data_equal (list1, shorty));
+        g_assert (!tracker_gslist_with_string_data_equal (shorty, list1));
+
+        list2 = g_slist_prepend (list2, g_strdup ("one"));
+        list2 = g_slist_prepend (list2, g_strdup ("two"));
+        list2 = g_slist_prepend (list2, g_strdup ("three"));
+        g_assert (tracker_gslist_with_string_data_equal (list1, list2));
+        g_assert (tracker_gslist_with_string_data_equal (list2, list1));
+
+        list3 = g_slist_prepend (list3, g_strdup ("one"));
+        list3 = g_slist_prepend (list3, g_strdup ("something different"));
+        list3 = g_slist_prepend (list3, g_strdup ("three"));
+        g_assert (!tracker_gslist_with_string_data_equal (list1, list3));
+        g_assert (!tracker_gslist_with_string_data_equal (list3, list1));
+
+        g_slist_foreach (list1, (GFunc)g_free, NULL);
+        g_slist_foreach (list2, (GFunc)g_free, NULL);
+        g_slist_foreach (shorty, (GFunc)g_free, NULL);
+        g_slist_foreach (list3, (GFunc)g_free, NULL);
+
+        g_slist_free (list1);
+        g_slist_free (list2);
+        g_slist_free (shorty);
+        g_slist_free (list3);
+}
+
+static void
+test_glist_copy_with_string_data (void)
+{
+        GList *input = NULL; 
+        GList *result = NULL;
+
+        input = g_list_prepend (input, g_strdup ("one"));
+        input = g_list_prepend (input, g_strdup ("two"));
+
+        result = tracker_glist_copy_with_string_data (input);
+        g_assert (result != input);
+        g_assert_cmpint (g_list_length (result), ==, 2);
+
+        /* Further checks... that the contents are actually the same */
+}
+
 int
 main (int argc, char **argv)
 {
@@ -372,10 +490,16 @@ main (int argc, char **argv)
 	                 test_boolean_as_text_to_number);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_as_list",
 	                 test_string_list_to_string);
+	g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_as_list",
+	                 test_string_to_string_list);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/gslist_to_string_list",
 	                 test_gslist_to_string_list);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list",
 	                 test_string_in_string_list);
+        g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_gslist",
+                         test_string_in_gslist);
+        g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_to_gslist",
+                         test_string_list_to_gslist);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_uint",
 	                 test_string_to_uint);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/guint32_to_string",
@@ -392,6 +516,10 @@ main (int argc, char **argv)
 	                 test_date_to_string);
 	g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_date",
 	                 test_string_to_date);
+	g_test_add_func ("/libtracker-common/tracker-type-utils/gslist_with_string_data_equal",
+	                 test_gslist_with_string_data_equal);
+	g_test_add_func ("/libtracker-common/tracker-type-utils/glist_copy_with_string_data",
+	                 test_glist_copy_with_string_data);
 	result = g_test_run ();
 
 	return result;



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