[tracker/domain-specific-indexes-review: 18/21] tests/libtracker-data: Allow tests inbetween ontology change phases



commit 4ee4031a429a56ab7f97a0a52b008aa868a0d43f
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Jul 13 16:19:35 2010 +0200

    tests/libtracker-data: Allow tests inbetween ontology change phases

 tests/libtracker-data/change/change-test-1.out |    1 +
 tests/libtracker-data/change/change-test-1.rq  |    1 +
 tests/libtracker-data/change/change-test-2.out |    3 +
 tests/libtracker-data/change/change-test-2.rq  |    3 +
 tests/libtracker-data/tracker-ontology-test.c  |  126 +++++++++++++++---------
 5 files changed, 86 insertions(+), 48 deletions(-)
---
diff --git a/tests/libtracker-data/change/change-test-1.out b/tests/libtracker-data/change/change-test-1.out
new file mode 100644
index 0000000..f27b76c
--- /dev/null
+++ b/tests/libtracker-data/change/change-test-1.out
@@ -0,0 +1 @@
+"1"
diff --git a/tests/libtracker-data/change/change-test-1.rq b/tests/libtracker-data/change/change-test-1.rq
new file mode 100644
index 0000000..17754c5
--- /dev/null
+++ b/tests/libtracker-data/change/change-test-1.rq
@@ -0,0 +1 @@
+select ?s1 { <a02> example:single1 ?s1 }
diff --git a/tests/libtracker-data/change/change-test-2.out b/tests/libtracker-data/change/change-test-2.out
new file mode 100644
index 0000000..f0ceea2
--- /dev/null
+++ b/tests/libtracker-data/change/change-test-2.out
@@ -0,0 +1,3 @@
+"1"
+~
+"2"
diff --git a/tests/libtracker-data/change/change-test-2.rq b/tests/libtracker-data/change/change-test-2.rq
new file mode 100644
index 0000000..4e8f2fb
--- /dev/null
+++ b/tests/libtracker-data/change/change-test-2.rq
@@ -0,0 +1,3 @@
+select ?s1 { <a02> example:single1 ?s1 }
+~
+select ?s2 { <a02> example:single2 ?s2 }
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index d7f6cc9..1776e16 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -44,6 +44,8 @@ typedef struct _ChangeInfo ChangeInfo;
 struct _ChangeInfo {
 	const gchar *ontology;
 	const gchar *update;
+	const gchar *test_name;
+	const gchar *ptr;
 };
 
 const TestInfo nie_tests[] = {
@@ -91,12 +93,12 @@ const TestInfo change_tests[] = {
 };
 
 const ChangeInfo changes[] = {
-	{ "99-example.ontology.v1", "99-example.queries.v1" },
-	{ "99-example.ontology.v2", "99-example.queries.v2" },
-	{ "99-example.ontology.v3", "99-example.queries.v3" },
-	{ "99-example.ontology.v4", "99-example.queries.v4" },
-	{ "99-example.ontology.v5", "99-example.queries.v5" },
-	{ "99-example.ontology.v6", "99-example.queries.v6" },
+	{ "99-example.ontology.v1", "99-example.queries.v1", NULL, NULL },
+	{ "99-example.ontology.v2", "99-example.queries.v2", NULL, NULL },
+	{ "99-example.ontology.v3", "99-example.queries.v3", NULL, NULL },
+	{ "99-example.ontology.v4", "99-example.queries.v4", NULL, NULL },
+	{ "99-example.ontology.v5", "99-example.queries.v5", "change/change-test-1", NULL },
+	{ "99-example.ontology.v6", "99-example.queries.v6", "change/change-test-2", NULL },
 	{ NULL }
 };
 
@@ -126,13 +128,12 @@ delete_db (gboolean del_journal)
 static void
 query_helper (const gchar *query_filename, const gchar *results_filename)
 {
-	TrackerDBResultSet *result_set;
 	GError *error = NULL;
-	gchar *query = NULL;
+	gchar *queries = NULL, *query;
 	gchar *results = NULL;
-	GString *test_results;
+	GString *test_results = NULL;
 
-	g_file_get_contents (query_filename, &query, NULL, &error);
+	g_file_get_contents (query_filename, &queries, NULL, &error);
 	g_assert_no_error (error);
 
 	g_file_get_contents (results_filename, &results, NULL, &error);
@@ -140,52 +141,64 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
 
 	/* perform actual query */
 
-	result_set = tracker_data_query_sparql (query, &error);
-	g_assert_no_error (error);
-
-	/* compare results with reference output */
-
-	test_results = g_string_new ("");
+	query = strtok (queries, "~");
 
-	if (result_set) {
-		gboolean valid = TRUE;
-		guint col_count;
-		gint col;
+	while (query) {
+		TrackerDBResultSet *result_set;
 
-		col_count = tracker_db_result_set_get_n_columns (result_set);
+		result_set = tracker_data_query_sparql (query, &error);
+		g_assert_no_error (error);
 
-		while (valid) {
-			for (col = 0; col < col_count; col++) {
-				GValue value = { 0 };
+		/* compare results with reference output */
 
-				_tracker_db_result_set_get_value (result_set, col, &value);
+		if (!test_results) {
+			test_results = g_string_new ("");
+		} else {
+			g_string_append (test_results, "~\n");
+		}
 
-				switch (G_VALUE_TYPE (&value)) {
-				case G_TYPE_INT64:
-					g_string_append_printf (test_results, "\"%" G_GINT64_FORMAT "\"", g_value_get_int64 (&value));
-					break;
-				case G_TYPE_DOUBLE:
-					g_string_append_printf (test_results, "\"%f\"", g_value_get_double (&value));
-					break;
-				case G_TYPE_STRING:
-					g_string_append_printf (test_results, "\"%s\"", g_value_get_string (&value));
-					break;
-				default:
-					/* unbound variable */
-					break;
+		if (result_set) {
+			gboolean valid = TRUE;
+			guint col_count;
+			gint col;
+
+			col_count = tracker_db_result_set_get_n_columns (result_set);
+
+			while (valid) {
+				for (col = 0; col < col_count; col++) {
+					GValue value = { 0 };
+
+					_tracker_db_result_set_get_value (result_set, col, &value);
+
+					switch (G_VALUE_TYPE (&value)) {
+					case G_TYPE_INT64:
+						g_string_append_printf (test_results, "\"%" G_GINT64_FORMAT "\"", g_value_get_int64 (&value));
+						break;
+					case G_TYPE_DOUBLE:
+						g_string_append_printf (test_results, "\"%f\"", g_value_get_double (&value));
+						break;
+					case G_TYPE_STRING:
+						g_string_append_printf (test_results, "\"%s\"", g_value_get_string (&value));
+						break;
+					default:
+						/* unbound variable */
+						break;
+					}
+
+					if (col < col_count - 1) {
+						g_string_append (test_results, "\t");
+					}
 				}
 
-				if (col < col_count - 1) {
-					g_string_append (test_results, "\t");
-				}
-			}
+				g_string_append (test_results, "\n");
 
-			g_string_append (test_results, "\n");
+				valid = tracker_db_result_set_iter_next (result_set);
+			}
 
-			valid = tracker_db_result_set_iter_next (result_set);
+			g_object_unref (result_set);
 		}
 
-		g_object_unref (result_set);
+			query = strtok (NULL, "~");
 	}
 
 	if (strcmp (results, test_results->str)) {
@@ -214,7 +227,7 @@ query_helper (const gchar *query_filename, const gchar *results_filename)
 
 	g_string_free (test_results, TRUE);
 	g_free (results);
-	g_free (query);
+	g_free (queries);
 }
 
 static void
@@ -264,9 +277,9 @@ test_ontology_change (void)
 		g_free (to);
 
 		g_file_copy (file1, file2, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
-                g_assert_no_error (error);
 
-                g_chmod (ontology_file, 0666);
+		g_assert_no_error (error);
+		g_chmod (ontology_file, 0666);
 
 		tracker_data_manager_init (0, (const gchar **) test_schemas,
 		                           NULL, FALSE, NULL, NULL, NULL);
@@ -289,6 +302,23 @@ test_ontology_change (void)
 		g_free (source);
 		g_object_unref (file1);
 
+
+		if (changes[i].test_name) {
+			gchar *query_filename;
+			gchar *results_filename;
+			gchar *test_prefix;
+
+			test_prefix = g_build_filename (prefix, changes[i].test_name, NULL);
+			query_filename = g_strconcat (test_prefix, ".rq", NULL);
+			results_filename = g_strconcat (test_prefix, ".out", NULL);
+
+			query_helper (query_filename, results_filename);
+
+			g_free (test_prefix);
+			g_free (query_filename);
+			g_free (results_filename);
+		}
+
 		tracker_data_manager_shutdown ();
 	}
 



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