[tracker/rss-enclosures] Fix issues in return-types, caught by unit tests and other testing



commit 08fbdd9c22a01d8554a36328981bce8a993e8d8a
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Sep 10 16:27:02 2010 +0200

    Fix issues in return-types, caught by unit tests and other testing

 src/libtracker-bus/tracker-bus-fd-cursor.c         |   20 +++++++++++++++++---
 src/libtracker-data/tracker-sparql-expression.vala |    1 -
 tests/tracker-steroids/tracker-test.c              |    4 +++-
 3 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index f24961d..4575d9c 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -178,6 +178,9 @@ tracker_bus_fd_cursor_get_value_type (TrackerBusFDCursor *cursor,  guint column)
 static const gchar*
 tracker_bus_fd_cursor_get_variable_name (TrackerBusFDCursor *cursor,  guint column)
 {
+	if (!cursor->variable_names)
+		return NULL;
+
 	return cursor->variable_names[column];
 }
 
@@ -193,6 +196,7 @@ tracker_bus_fd_cursor_get_string (TrackerBusFDCursor *cursor,
 	}
 
 	g_return_val_if_fail (column < tracker_bus_fd_cursor_get_n_columns (cursor), NULL);
+	g_return_val_if_fail (cursor->data != NULL, NULL);
 
 	if (column == 0) {
 		str = cursor->data;
@@ -295,7 +299,12 @@ tracker_bus_fd_query (DBusGConnection  *gconnection,
 	                              &cursor->variable_names,
 	                              &inner_error);
 
-	cursor->n_columns = g_strv_length (cursor->variable_names);
+	if (cursor->variable_names) {
+		cursor->n_columns = g_strv_length (cursor->variable_names);
+	} else {
+		cursor->variable_names = NULL;
+		cursor->n_columns = 0;
+	}
 
 	/* message is destroyed by tracker_dbus_send_and_splice */
 
@@ -337,8 +346,13 @@ query_async_cb (gpointer  buffer,
 
 		cursor->buffer = buffer;
 		cursor->buffer_size = buffer_size;
-		cursor->variable_names = g_strdupv (variable_names);
-		cursor->n_columns = g_strv_length (cursor->variable_names);
+		if (variable_names) {
+			cursor->variable_names = g_strdupv (variable_names);
+			cursor->n_columns = g_strv_length (cursor->variable_names);
+		} else {
+			cursor->variable_names = NULL;
+			cursor->n_columns = 0;
+		}
 
 		g_simple_async_result_set_op_res_gpointer (res, cursor, g_object_unref);
 	}
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 0e8161b..4a4af2f 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -135,7 +135,6 @@ class Tracker.Sparql.Expression : Object {
 
 		if (!subquery) {
 			convert_expression_to_string (sql, type, begin);
-			type = PropertyType.STRING;
 		}
 
 		if (accept (SparqlTokenType.AS)) {
diff --git a/tests/tracker-steroids/tracker-test.c b/tests/tracker-steroids/tracker-test.c
index 720819f..39f4680 100644
--- a/tests/tracker-steroids/tracker-test.c
+++ b/tests/tracker-steroids/tracker-test.c
@@ -232,7 +232,9 @@ test_tracker_sparql_query_iterate_empty ()
 	g_assert_no_error (error);
 
 	g_assert (!tracker_sparql_cursor_next (cursor, NULL, NULL));
-	g_assert (!tracker_sparql_cursor_get_n_columns (cursor));
+	/* This should be 1, the original test had it wrong: there's one column,
+	 * no matter if there are no results*/
+	g_assert (tracker_sparql_cursor_get_n_columns (cursor) == 1);
 	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) {
 		tracker_sparql_cursor_get_string (cursor, 0, NULL);
 		exit (0);



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