[tracker/dbus-fd-experiment: 4/4] Add tests for Tracker Steroids



commit 6913c1aea2f27db6f409ff4a5c2fd807bcf03e56
Author: Adrien Bustany <abustany gnome org>
Date:   Wed May 26 15:22:18 2010 -0400

    Add tests for Tracker Steroids
    
    This commit adds test for all the functions introduced in tracker-store
    and libtracker-client to handle the new Steroids interface. Coverage has
    been verified using gcov.

 configure.ac                          |    1 +
 tests/Makefile.am                     |    3 +-
 tests/tracker-steroids/Makefile.am    |   30 +++++
 tests/tracker-steroids/tracker-test.c |  210 +++++++++++++++++++++++++++++++++
 4 files changed, 243 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 83301d6..ec641fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1949,6 +1949,7 @@ AC_CONFIG_FILES([
 	tests/Makefile
 	tests/tracker-miner-fs/Makefile
 	tests/tracker-extract/Makefile
+	tests/tracker-steroids/Makefile
 	tests/tracker-store/Makefile
 	tests/tracker-writeback/Makefile
 	utils/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3b90efb..b7daa7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,9 +11,10 @@ SUBDIRS = 			\
 	libtracker-fts 		\
 	tracker-miner-fs	\
 	tracker-extract		\
+	tracker-steroids	\
 	tracker-store		\
 	tracker-writeback
 
 if DIST_FUNCTIONAL_TESTS
 SUBDIRS += functional-tests
-endif
\ No newline at end of file
+endif
diff --git a/tests/tracker-steroids/Makefile.am b/tests/tracker-steroids/Makefile.am
new file mode 100644
index 0000000..d437a69
--- /dev/null
+++ b/tests/tracker-steroids/Makefile.am
@@ -0,0 +1,30 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS += 								\
+	tracker-test
+
+INCLUDES = 								\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
+	-DTRACKER_COMPILATION						\
+	-I$(top_srcdir)/src						\
+	-I$(top_srcdir)/tests/common					\
+	$(WARN_CFLAGS)							\
+	$(GLIB2_CFLAGS)							\
+	$(GCOV_CFLAGS)							\
+	$(GMODULE_CFLAGS)						\
+	$(GTHREAD_CFLAGS)						\
+	$(DBUS_CFLAGS)
+
+tracker_test_SOURCES = 							\
+	tracker-test.c
+
+tracker_test_LDADD = 							\
+	$(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+	$(DBUS_LIBS)							\
+	$(GMODULE_LIBS)							\
+	$(GTHREAD_LIBS)							\
+	$(GIO_LIBS)							\
+	$(GLIB2_LIBS)							\
+	$(GCOV_LIBS)
\ No newline at end of file
diff --git a/tests/tracker-steroids/tracker-test.c b/tests/tracker-steroids/tracker-test.c
new file mode 100644
index 0000000..2a4592c
--- /dev/null
+++ b/tests/tracker-steroids/tracker-test.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+#include <glib.h>
+#include <libtracker-client/tracker.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This MUST be larger than TRACKER_STEROIDS_BUFFER_SIZE */
+#define LONG_NAME_SIZE 128*1024*sizeof(char)
+
+static TrackerClient *client;
+
+static void
+insert_test_data ()
+{
+	GError *error = NULL;
+	const char *delete_query = "DELETE { "
+                               "<urn:testdata1> a rdfs:Resource ."
+                               "<urn:testdata2> a rdfs:Resource ."
+                               "<urn:testdata3> a rdfs:Resource ."
+                               "<urn:testdata4> a rdfs:Resource ."
+                               "}";
+	const char *query = "INSERT {"
+	                    "    <urn:testdata1> a nfo:FileDataObject ; nie:url \"/foo/bar\" ."
+	                    "    <urn:testdata2> a nfo:FileDataObject ; nie:url \"/plop/coin\" ."
+	                    "    <urn:testdata3> a nmm:Artist ; nmm:artistName \"testArtist\" ."
+                        "    <urn:testdata4> a nmm:Photo ; nao:identifier \"%s\" ."
+	                    "}";
+	char *longName = g_malloc (LONG_NAME_SIZE);
+	char *filled_query;
+
+	//memset (longName, 'a', LONG_NAME_SIZE);
+
+	int i;
+	for (i = 0; i < LONG_NAME_SIZE; i++)
+		longName[i] = (0x61 + i%26);
+
+	longName[LONG_NAME_SIZE - 1] = '\0';
+
+	filled_query = g_strdup_printf (query, longName);
+
+	tracker_resources_sparql_update (client, delete_query, NULL);
+	tracker_resources_sparql_update (client, filled_query, &error);
+
+	g_free (filled_query);
+
+	g_assert (!error);
+}
+
+/* Runs the same query using the iterate and traditional interface, and compare
+ * the results */
+static void
+test_tracker_sparql_query_iterate ()
+{
+	GPtrArray *r1;
+	TrackerResultIterator *iterator;
+	GError *error = NULL;
+	const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject}";
+	guint i = 0;
+
+	r1 = tracker_resources_sparql_query (client, query, &error);
+
+	g_assert (!error);
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	g_assert (!error);
+
+	while (tracker_result_iterator_has_next (iterator)) {
+		GStrv row;
+
+		g_assert (i < r1->len);
+
+		tracker_result_iterator_next (iterator);
+		row = g_ptr_array_index (r1, i++);
+
+		g_assert (!g_strcmp0 (tracker_result_iterator_value (iterator, 0), row[0]));
+	}
+
+	tracker_result_iterator_free (iterator);
+}
+
+/* Runs the same query using the iterate and traditional interface, and compare
+ * the results */
+static void
+test_tracker_sparql_query_iterate_largerow ()
+{
+	GPtrArray *r1;
+	TrackerResultIterator *iterator;
+	GError *error = NULL;
+	const gchar *query = "SELECT nao:identifier(?r) WHERE {?r a nmm:Photo}";
+	guint i = 0;
+
+	r1 = tracker_resources_sparql_query (client, query, &error);
+
+	g_assert (!error);
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	g_assert (!error);
+
+	while (tracker_result_iterator_has_next (iterator)) {
+		GStrv row;
+
+		g_assert (i < r1->len);
+
+		tracker_result_iterator_next (iterator);
+		row = g_ptr_array_index (r1, i++);
+
+		g_assert (!g_strcmp0 (tracker_result_iterator_value (iterator, 0), row[0]));
+	}
+
+	tracker_result_iterator_free (iterator);
+}
+
+/* Runs an invalid query */
+static void
+test_tracker_sparql_query_iterate_error ()
+{
+	TrackerResultIterator *iterator;
+	GError *error = NULL;
+	const gchar *query = "bork bork bork";
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	/* tracker_sparql_query_iterate should return null on error */
+	g_assert (!iterator);
+	/* error should be set, along with its message */
+	g_assert (error && error->message);
+
+	g_error_free (error);
+}
+
+/* Runs a query returning an empty set */
+static void
+test_tracker_sparql_query_iterate_empty ()
+{
+	TrackerResultIterator *iterator;
+	GError *error = NULL;
+	const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier \"thisannotationdoesnotexist\"}";
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	g_assert (iterator);
+	g_assert (!error);
+
+	g_assert (!tracker_result_iterator_has_next (iterator));
+	g_assert (!tracker_result_iterator_n_columns (iterator));
+	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) {
+		tracker_result_iterator_value (iterator, 0);
+		exit (0);
+	}
+	g_test_trap_assert_failed ();
+	/* And just to make coverage happy... */
+	tracker_result_iterator_next (iterator);
+}
+
+static void
+test_tracker_sparql_query_iterate_sigpipe ()
+{
+	TrackerResultIterator *iterator;
+	GError *error = NULL;
+	const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject}";
+
+	iterator = tracker_resources_sparql_query_iterate (client, query, &error);
+
+	g_assert (iterator);
+	g_assert (!error);
+
+	tracker_result_iterator_next (iterator);
+
+	return;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+        g_type_init ();
+        g_test_init (&argc, &argv, NULL);
+
+		client = tracker_client_new (0, -1);
+
+		insert_test_data ();
+
+        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate", test_tracker_sparql_query_iterate);
+        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_largerow", test_tracker_sparql_query_iterate_largerow);
+        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_error", test_tracker_sparql_query_iterate_error);
+        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_empty", test_tracker_sparql_query_iterate_empty);
+        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_sigpipe", test_tracker_sparql_query_iterate_sigpipe);
+
+		// client is leaked
+
+        return g_test_run ();
+}



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