[tracker/harmattan-pre-signal-updates: 1289/1380] libtracker-sparql: Added cursor_next_async() test case



commit 32fdefe4f947936a00aab3ec7b6dd7854e098bcc
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Sep 13 12:22:34 2010 +0100

    libtracker-sparql: Added cursor_next_async() test case
    
    Currently causes a crash running 2 queries at the same time

 tests/libtracker-sparql/tracker-test.c |  154 ++++++++++++++++++++++++++------
 1 files changed, 126 insertions(+), 28 deletions(-)
---
diff --git a/tests/libtracker-sparql/tracker-test.c b/tests/libtracker-sparql/tracker-test.c
index 1f8d138..804aa7d 100644
--- a/tests/libtracker-sparql/tracker-test.c
+++ b/tests/libtracker-sparql/tracker-test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ * Copyright (C) 2010, 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
@@ -16,52 +16,150 @@
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA  02110-1301, USA.
  */
-#include <glib.h>
+
 #include <tracker-sparql.h>
 
 typedef struct {
-        const gchar *input ;
-        const gchar *output;
+	const gchar *input ;
+	const gchar *output;
 } ESCAPE_TEST_DATA;
 
-ESCAPE_TEST_DATA  test_data []  = {
-        {"SELECT \"a\"", "SELECT \\\"a\\\""},
-        {"SELECT ?u \t \n \r \b \f", "SELECT ?u \\t \\n \\r \\b \\f"},
-        {NULL, NULL }
+ESCAPE_TEST_DATA test_data []  = {
+	{ "SELECT \"a\"", "SELECT \\\"a\\\"" },
+	{ "SELECT ?u \t \n \r \b \f", "SELECT ?u \\t \\n \\r \\b \\f" },
+	{ NULL, NULL }
 };
 
+static TrackerSparqlConnection *connection;
+static GMainLoop *main_loop;
+
+static void
+test_tracker_sparql_escape_string (void)
+{
+	gint i;
+	gchar *result;
+
+	for (i = 0; test_data[i].input != NULL; i++) {
+		result = tracker_sparql_escape_string (test_data[i].input);
+		g_assert_cmpstr (result, ==, test_data[i].output);
+		g_free (result);
+	}
+}
+
+static void
+test_tracker_sparql_escape_uri_vprintf (void)
+{
+	gchar *result;
+
+	result = tracker_sparql_escape_uri_printf ("test:uri:contact-%d", 14, NULL);
+	g_assert_cmpstr (result, ==, "test:uri:contact-14");
+	g_free (result);
+}
+
 static void
-test_tracker_sparql_escape_string ()
+test_tracker_sparql_cursor_next_async_cb (GObject      *source,
+                                          GAsyncResult *result,
+                                          gpointer      user_data)
 {
-        gint i;
-        gchar *result;
-
-        for (i = 0; test_data[i].input != NULL; i++) {
-                result = tracker_sparql_escape_string (test_data[i].input);
-                g_assert_cmpstr (result, ==, test_data[i].output);
-                g_free (result);
-        }
+	TrackerSparqlCursor *cursor;
+	GError *error = NULL;
+	gboolean success;
+	static gint successes = 0;
+
+	g_assert (result != NULL);
+	success = tracker_sparql_cursor_next_finish (TRACKER_SPARQL_CURSOR (source), result, &error);
+	g_assert_no_error (error);
+
+	cursor = TRACKER_SPARQL_CURSOR (source);
+	g_assert (cursor != NULL);
+
+	g_print ("  %p: %s\n", user_data, tracker_sparql_cursor_get_string (cursor, 0, NULL));
+
+	if (!success) {
+		successes++;
+		if (successes > 1) {
+			g_main_loop_quit (main_loop);
+		}
+	} else {
+		tracker_sparql_cursor_next_async (cursor, NULL, test_tracker_sparql_cursor_next_async_cb, user_data);
+	}
 }
 
 static void
-test_tracker_sparql_escape_uri_vprintf ()
+test_tracker_sparql_cursor_next_async (void)
 {
-        gchar *result;
+	TrackerSparqlCursor *cursor;
+	GError *error = NULL;
+	const gchar *query1 = "SELECT ?p WHERE { ?p tracker:indexed true }";
+	const gchar *query2 = "SELECT"
+			     "  ?song"
+			     "  nie:url(?song)"
+			     "  tracker:coalesce(nie:title(?song), nfo:fileName(?song), \"Unknown\")"
+			     "  fn:string-join((?performer, ?album), \" - \")"
+			     "  nfo:duration(?song)"
+			     "  ?tooltip "
+			     "WHERE {"
+			     "  ?match fts:match \"love\""
+			     "  {"
+			     "    ?song nmm:musicAlbum ?match"
+			     "  } UNION {"
+			     "    ?song nmm:performer ?match"
+			     "  } UNION {"
+			     "    ?song a nfo:Audio ."
+			     "    ?match a nfo:Audio"
+			     "    FILTER (?song = ?match)"
+			     "  }"
+			     "  ?song nmm:performer [ nmm:artistName ?performer ] ;"
+			     "        nmm:musicAlbum [ nie:title ?album ] ;"
+			     "        nfo:belongsToContainer [ nie:url ?tooltip ]"
+			     "} "
+			     "ORDER BY DESC(fts:rank(?song)) DESC(nie:title(?song)) "
+			     "OFFSET 0 LIMIT 100";
+
+	
+	g_print ("ASYNC query 1 starting:\n");
+	cursor = tracker_sparql_connection_query (connection, query1, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (cursor != NULL);
+	tracker_sparql_cursor_next_async (cursor, NULL, test_tracker_sparql_cursor_next_async_cb, GINT_TO_POINTER(1));
 
-        result = tracker_sparql_escape_uri_printf ("test:uri:contact-%d", 14, NULL);
-        g_assert_cmpstr (result, ==, "test:uri:contact-14");
-        g_free (result);
+	g_print ("ASYNC query 2 starting:\n");
+	cursor = tracker_sparql_connection_query (connection, query2, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (cursor != NULL);
+	tracker_sparql_cursor_next_async (cursor, NULL, test_tracker_sparql_cursor_next_async_cb, GINT_TO_POINTER(2));
 }
 
 gint
 main (gint argc, gchar **argv)
 {
-        g_type_init ();
-        g_test_init (&argc, &argv, NULL);
+	int result;
+	GError *error = NULL;
+
+	g_thread_init (NULL);
+	g_type_init ();
+	g_test_init (&argc, &argv, NULL);
+
+	main_loop = g_main_loop_new (NULL, FALSE);
+	g_assert (main_loop != NULL);
+
+	connection = tracker_sparql_connection_get (&error);
+
+	g_assert_no_error (error);
+	g_assert (connection != NULL);
+
+	g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_string", 
+	                 test_tracker_sparql_escape_string);
+	g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_uri_vprintf",
+	                 test_tracker_sparql_escape_uri_vprintf);
+	g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_cursor_next_async",
+	                 test_tracker_sparql_cursor_next_async);
+
+	result = g_test_run ();
+
+	g_main_loop_run (main_loop);
 
-        g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_string", test_tracker_sparql_escape_string);
-        g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_uri_vprintf",
-                         test_tracker_sparql_escape_uri_vprintf);
+	g_object_unref (connection);
 
-        return g_test_run ();
+	return result;
 }



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