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



Author: ifrade
Date: Tue Jul  1 13:25:43 2008
New Revision: 1810
URL: http://svn.gnome.org/viewvc/tracker?rev=1810&view=rev

Log:
Unit tests for some tracker-file-utils functions

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

Modified: branches/indexer-split/tests/common/tracker-test-helpers.c
==============================================================================
--- branches/indexer-split/tests/common/tracker-test-helpers.c	(original)
+++ branches/indexer-split/tests/common/tracker-test-helpers.c	Tue Jul  1 13:25:43 2008
@@ -40,3 +40,29 @@
 		return FALSE;
 	}
 }
+
+static gchar *nonutf8_str = NULL;
+
+const gchar *  
+tracker_test_helpers_get_nonutf8 ()
+{
+        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);
+        }
+
+	return nonutf8_str;
+}
+
+void
+tracker_test_helpers_free_nonutf8 ()
+{
+	if (nonutf8_str) {
+		g_free (nonutf8_str);
+		nonutf8_str = NULL;
+	}
+}

Modified: branches/indexer-split/tests/common/tracker-test-helpers.h
==============================================================================
--- branches/indexer-split/tests/common/tracker-test-helpers.h	(original)
+++ branches/indexer-split/tests/common/tracker-test-helpers.h	Tue Jul  1 13:25:43 2008
@@ -22,7 +22,10 @@
 
 #include <glib.h>
 
-gboolean tracker_test_helpers_cmpstr_equal (const gchar *obtained, 
-                                            const gchar *expected);
+gboolean     tracker_test_helpers_cmpstr_equal (const gchar *obtained,
+						const gchar *expected);
+const gchar *tracker_test_helpers_get_nonutf8  ();
+void         tracker_test_helpers_free_nonutf8 ();
+
 
 #endif

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	Tue Jul  1 13:25:43 2008
@@ -2,7 +2,7 @@
 
 noinst_PROGRAMS = $(TEST_PROGS)
 
-TEST_PROGS += tracker-ontology tracker-dbus tracker-type-utils
+TEST_PROGS += tracker-ontology tracker-dbus tracker-type-utils tracker-file-utils
 
 INCLUDES = 				\
 	-g 				\
@@ -32,6 +32,7 @@
 
 tracker_dbus_LDADD =							\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
+	$(top_builddir)/tests/common/libtracker-testcommon.la 		\
 	$(DBUS_LIBS)							\
 	$(GMODULE_LIBS)							\
 	$(GTHREAD_LIBS)							\
@@ -46,3 +47,14 @@
 	$(GMODULE_LIBS)							\
 	$(GTHREAD_LIBS)							\
 	$(GLIB2_LIBS)							
+
+tracker_file_utils_SOURCES = \
+	tracker-file-utils-test.c 
+
+tracker_file_utils_LDADD =						\
+	$(top_builddir)/src/libtracker-common/libtracker-common.la 	\
+	$(top_builddir)/tests/common/libtracker-testcommon.la 		\
+	$(top_builddir)/src/xdgmime/libxdgmime.la 			\
+	$(GMODULE_LIBS)							\
+	$(GTHREAD_LIBS)							\
+	$(GLIB2_LIBS)							

Modified: branches/indexer-split/tests/libtracker-common/non-utf8.txt
==============================================================================
--- branches/indexer-split/tests/libtracker-common/non-utf8.txt	(original)
+++ branches/indexer-split/tests/libtracker-common/non-utf8.txt	Tue Jul  1 13:25:43 2008
@@ -1 +1 @@
-Non UTF-8: ä90808.
+/invalid/file/ä90808.

Modified: branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c
==============================================================================
--- branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c	(original)
+++ branches/indexer-split/tests/libtracker-common/tracker-dbus-test.c	Tue Jul  1 13:25:43 2008
@@ -20,21 +20,8 @@
 #include <glib.h>
 #include <glib/gtestutils.h>
 #include <libtracker-common/tracker-dbus.h>
+#include <tracker-test-helpers.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) 
@@ -48,7 +35,7 @@
                 if (utf8) {
                         input = g_slist_prepend (input, g_strdup_printf ("%d", i));
                 } else {
-                        input = g_slist_prepend (input, g_strdup (nonutf8_str));
+                        input = g_slist_prepend (input, g_strdup (tracker_test_helpers_get_nonutf8 ()));
                 }
         }
         g_assert_cmpint (g_slist_length (input), ==, strings);
@@ -89,7 +76,7 @@
                 if (utf8) {
                         g_async_queue_push (queue, g_strdup_printf ("%d", i));
                 } else {
-                        g_async_queue_push (queue, g_strdup (nonutf8_str));
+                        g_async_queue_push (queue, g_strdup (tracker_test_helpers_get_nonutf8 ()));
                 }
         }
         g_assert_cmpint (g_async_queue_length (queue), ==, strings);
@@ -127,8 +114,6 @@
         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);
@@ -136,7 +121,7 @@
 
         result = g_test_run ();
         
-        g_free (nonutf8_str);
+	tracker_test_helpers_free_nonutf8 ();
         
         return result;
 }



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