tracker r1677 - in branches/indexer-split: . src/libtracker-common tests/libtracker-common



Author: ifrade
Date: Fri Jun 13 14:25:52 2008
New Revision: 1677
URL: http://svn.gnome.org/viewvc/tracker?rev=1677&view=rev

Log:
Added test to libtracker-common/tracker-dbus.h helper methods using non utf8 strings

Added:
   branches/indexer-split/tests/libtracker-common/non-utf8.txt
   branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c
Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-dbus.c
   branches/indexer-split/tests/libtracker-common/Makefile.am

Modified: branches/indexer-split/src/libtracker-common/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-dbus.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-dbus.c	Fri Jun 13 14:25:52 2008
@@ -72,7 +72,7 @@
 				
         for (l = list; l != NULL; l = l->next) {
 		if (!g_utf8_validate (l->data, -1, NULL)) {
-			g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", 
+			g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", 
 				   (gchar*) l->data);
 			continue;
 		}
@@ -113,7 +113,7 @@
 
 		if (str) {
 			if (!g_utf8_validate (str, -1, NULL)) {
-				g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
+				g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
 				g_free (str);
 				continue;
 			}

Modified: branches/indexer-split/tests/libtracker-common/Makefile.am
==============================================================================
--- branches/indexer-split/tests/libtracker-common/Makefile.am	(original)
+++ branches/indexer-split/tests/libtracker-common/Makefile.am	Fri Jun 13 14:25:52 2008
@@ -2,14 +2,15 @@
 
 noinst_PROGRAMS = $(TEST_PROGS)
 
-TEST_PROGS += tracker-ontology
+TEST_PROGS += tracker-ontology tracker-dbus
 
-INCLUDES = 			\
-	-g 			\
-	-DG_LOG_DOMAIN=\"Tracker\"					\
-	-I$(top_srcdir)/src						\
-	$(GMODULE_CFLAGS)						\
-	$(GTHREAD_CFLAGS)						\
+INCLUDES = 				\
+	-g 				\
+	-DG_LOG_DOMAIN=\"Tracker\"	\
+	-I$(top_srcdir)/src		\
+	$(DBUS_CFLAGS)			\
+	$(GMODULE_CFLAGS)		\
+	$(GTHREAD_CFLAGS)		\
 	$(GLIB2_CFLAGS)
 
 
@@ -17,8 +18,19 @@
 tracker_ontology_SOURCES = \
 	tracker-ontology-test.c
 
-tracker_ontology_LDADD =							\
+tracker_ontology_LDADD =						\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
 	$(GMODULE_LIBS)							\
 	$(GTHREAD_LIBS)							\
 	$(GLIB2_LIBS)							
+
+
+tracker_dbus_SOURCES = \
+	tracker-dbus-test.c
+
+tracker_dbus_LDADD =							\
+	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
+	$(DBUS_LIBS)							\
+	$(GMODULE_LIBS)							\
+	$(GTHREAD_LIBS)							\
+	$(GLIB2_LIBS)							

Added: branches/indexer-split/tests/libtracker-common/non-utf8.txt
==============================================================================
--- (empty file)
+++ branches/indexer-split/tests/libtracker-common/non-utf8.txt	Fri Jun 13 14:25:52 2008
@@ -0,0 +1 @@
+Non UTF-8: ä90808.

Added: branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c	Fri Jun 13 14:25:52 2008
@@ -0,0 +1,123 @@
+#include <glib.h>
+#include <glib/gtestutils.h>
+#include <libtracker-common/tracker-dbus.h>
+
+gchar * nonutf8_str = NULL;
+
+static void
+load_nonutf8_string ()
+{
+        GMappedFile *file = NULL;
+
+        if (!nonutf8_str) {
+                file = g_mapped_file_new ("./non-utf8.txt", FALSE, NULL);
+                nonutf8_str = g_strdup (g_mapped_file_get_contents (file));
+                nonutf8_str [g_mapped_file_get_length (file) -1] = '\0';
+                g_mapped_file_free (file);
+        }
+}
+
+static void
+slist_to_strv (gboolean utf8) 
+{
+        GSList *input = NULL;
+        gint    i;
+        gchar **input_as_strv;
+        gint    strings = 5;
+
+        for (i = 0; i < strings; i++) {
+                if (utf8) {
+                        input = g_slist_prepend (input, g_strdup_printf ("%d", i));
+                } else {
+                        input = g_slist_prepend (input, g_strdup (nonutf8_str));
+                }
+        }
+        g_assert_cmpint (g_slist_length (input), ==, strings);
+
+        input_as_strv = tracker_dbus_slist_to_strv (input);
+
+        g_assert_cmpint (g_strv_length (input_as_strv), ==, (utf8 ? strings : 0));
+
+        g_slist_foreach (input, (GFunc)g_free, NULL);
+        g_slist_free (input);
+
+        g_strfreev (input_as_strv);
+}
+
+static void
+test_slist_to_strv (void)
+{
+        slist_to_strv (TRUE);
+}
+
+static void
+test_slist_to_strv_nonutf8 (void)
+{
+        slist_to_strv (FALSE);
+}
+
+static void
+async_queue_to_strv (gboolean utf8)
+{
+        GAsyncQueue *queue;
+        gint i;
+        gchar **queue_as_strv;
+        gint strings = 5;
+
+        queue = g_async_queue_new ();
+
+        for (i = 0; i < strings; i++) {
+                if (utf8) {
+                        g_async_queue_push (queue, g_strdup_printf ("%d", i));
+                } else {
+                        g_async_queue_push (queue, g_strdup (nonutf8_str));
+                }
+        }
+        g_assert_cmpint (g_async_queue_length (queue), ==, strings);
+
+        queue_as_strv = tracker_dbus_async_queue_to_strv (queue, g_async_queue_length (queue));
+
+        g_assert_cmpint (g_strv_length (queue_as_strv), ==, (utf8 ? strings : 0));
+
+        // Queue empty by tracker_dbus_async_queue_to_strv
+        g_async_queue_unref (queue);
+        g_strfreev (queue_as_strv);
+
+}
+
+
+static void
+test_async_queue_to_strv (void)
+{
+        async_queue_to_strv (TRUE);
+}
+
+static void
+test_async_queue_to_strv_nonutf8 (void)
+{
+        async_queue_to_strv (FALSE);
+}
+
+
+int
+main (int argc, char **argv) {
+
+        int result;
+
+	g_type_init ();
+        g_thread_init (NULL);
+	g_test_init (&argc, &argv, NULL);
+
+        load_nonutf8_string ();
+
+        g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_ok", test_slist_to_strv);
+        g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_nonutf8", test_slist_to_strv_nonutf8);
+        g_test_add_func ("/libtracker-common/tracker-dbus/async_queue_to_strv_ok", test_async_queue_to_strv);
+        g_test_add_func ("/libtracker-common/tracker-dbus/async_queue_to_strv_nonutf8", test_async_queue_to_strv_nonutf8);
+
+        result = g_test_run ();
+        
+        g_free (nonutf8_str);
+        
+        return result;
+}



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