[tracker] libtracker-data: Fix tests to work with new TrackerFTSConfig
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] libtracker-data: Fix tests to work with new TrackerFTSConfig
- Date: Wed, 22 Jul 2009 08:39:55 +0000 (UTC)
commit 576d1c89182694c24095576f17ab86a062182041
Author: Jürg Billeter <j bitron ch>
Date: Wed Jul 22 09:43:16 2009 +0200
libtracker-data: Fix tests to work with new TrackerFTSConfig
tests/libtracker-data/tracker-ontology-test.c | 199 +++++++++++++------------
tests/libtracker-data/tracker-sparql-test.c | 201 +++++++++++++------------
2 files changed, 213 insertions(+), 187 deletions(-)
---
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 30ab95d..a01afef 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -85,119 +85,132 @@ consume_triple_storer (const gchar *subject,
static void
test_query (gconstpointer test_data)
{
- GError *error;
- gchar *data_filename;
- gchar *query, *query_filename;
- gchar *results, *results_filename;
- TrackerDBResultSet *result_set;
const TestInfo *test_info;
- GString *test_results;
- error = NULL;
test_info = test_data;
- /* initialization */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX | TRACKER_DB_MANAGER_TEST_MODE,
- NULL, NULL);
-
- /* load data set */
- data_filename = g_strconcat (test_info->data, ".ttl", NULL);
- tracker_data_begin_transaction ();
- tracker_turtle_process (data_filename, NULL, consume_triple_storer, NULL);
- tracker_data_commit_transaction ();
-
- query_filename = g_strconcat (test_info->test_name, ".rq", NULL);
- g_file_get_contents (query_filename, &query, NULL, &error);
- g_assert (error == NULL);
-
- results_filename = g_strconcat (test_info->test_name, ".out", NULL);
- g_file_get_contents (results_filename, &results, NULL, &error);
- g_assert (error == NULL);
-
- /* perform actual query */
-
- result_set = tracker_data_query_sparql (query, &error);
- g_assert (error == NULL);
-
- /* compare results with reference output */
-
- test_results = g_string_new ("");
-
- if (result_set) {
- gboolean valid = TRUE;
- guint col_count;
- gint col;
+ /* fork as tracker-fts can only be initialized once per process (GType in loadable module) */
+ if (g_test_trap_fork (0, 0)) {
+ int exitcode;
+ GError *error;
+ gchar *data_filename;
+ gchar *query, *query_filename;
+ gchar *results, *results_filename;
+ TrackerDBResultSet *result_set;
+ GString *test_results;
+
+ exitcode = 0;
+ error = NULL;
+
+ /* initialization */
+ tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX | TRACKER_DB_MANAGER_TEST_MODE,
+ NULL, NULL);
+
+ /* load data set */
+ data_filename = g_strconcat (test_info->data, ".ttl", NULL);
+ tracker_data_begin_transaction ();
+ tracker_turtle_process (data_filename, NULL, consume_triple_storer, NULL);
+ tracker_data_commit_transaction ();
+
+ query_filename = g_strconcat (test_info->test_name, ".rq", NULL);
+ g_file_get_contents (query_filename, &query, NULL, &error);
+ g_assert (error == NULL);
- col_count = tracker_db_result_set_get_n_columns (result_set);
+ results_filename = g_strconcat (test_info->test_name, ".out", NULL);
+ g_file_get_contents (results_filename, &results, NULL, &error);
+ g_assert (error == NULL);
- while (valid) {
- for (col = 0; col < col_count; col++) {
- GValue value = { 0 };
+ /* perform actual query */
- _tracker_db_result_set_get_value (result_set, col, &value);
+ result_set = tracker_data_query_sparql (query, &error);
+ g_assert (error == NULL);
- switch (G_VALUE_TYPE (&value)) {
- case G_TYPE_INT:
- g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&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;
+ /* compare results with reference output */
+
+ test_results = g_string_new ("");
+
+ 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_INT:
+ g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&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");
+
+ valid = tracker_db_result_set_iter_next (result_set);
}
- g_string_append (test_results, "\n");
+ g_object_unref (result_set);
+ }
- valid = tracker_db_result_set_iter_next (result_set);
+ if (strcmp (results, test_results->str)) {
+ /* print result difference */
+ gchar *quoted_results;
+ gchar *command_line;
+ gchar *quoted_command_line;
+ gchar *shell;
+ gchar *diff;
+
+ quoted_results = g_shell_quote (test_results->str);
+ command_line = g_strdup_printf ("echo -n %s | diff -u %s -", quoted_results, results_filename);
+ quoted_command_line = g_shell_quote (command_line);
+ shell = g_strdup_printf ("sh -c %s", quoted_command_line);
+ g_spawn_command_line_sync (shell, &diff, NULL, NULL, &error);
+ g_assert (error == NULL);
+
+ g_error ("%s", diff);
+
+ g_free (quoted_results);
+ g_free (command_line);
+ g_free (quoted_command_line);
+ g_free (shell);
+ g_free (diff);
+
+ exitcode = 1;
}
- g_object_unref (result_set);
- }
+ /* cleanup */
- if (strcmp (results, test_results->str)) {
- /* print result difference */
- gchar *quoted_results;
- gchar *command_line;
- gchar *quoted_command_line;
- gchar *shell;
- gchar *diff;
-
- quoted_results = g_shell_quote (test_results->str);
- command_line = g_strdup_printf ("echo -n %s | diff -u %s -", quoted_results, results_filename);
- quoted_command_line = g_shell_quote (command_line);
- shell = g_strdup_printf ("sh -c %s", quoted_command_line);
- g_spawn_command_line_sync (shell, &diff, NULL, NULL, &error);
- g_assert (error == NULL);
+ g_free (data_filename);
+ g_free (query_filename);
+ g_free (query);
+ g_free (results_filename);
+ g_free (results);
+ g_string_free (test_results, TRUE);
- g_error ("%s", diff);
+ tracker_data_manager_shutdown ();
- g_free (quoted_results);
- g_free (command_line);
- g_free (quoted_command_line);
- g_free (shell);
- g_free (diff);
+ exit (exitcode);
}
- /* cleanup */
-
- g_free (data_filename);
- g_free (query_filename);
- g_free (query);
- g_free (results_filename);
- g_free (results);
- g_string_free (test_results, TRUE);
-
- tracker_data_manager_shutdown ();
+ g_test_trap_assert_passed ();
}
int
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 6006fbb..98d00c0 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -72,120 +72,133 @@ consume_triple_storer (const gchar *subject,
static void
test_sparql_query (gconstpointer test_data)
{
- GError *error;
- gchar *data_filename;
- gchar *query, *query_filename;
- gchar *results, *results_filename;
- TrackerDBResultSet *result_set;
const TestInfo *test_info;
- GString *test_results;
- error = NULL;
test_info = test_data;
- /* initialization */
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX | TRACKER_DB_MANAGER_TEST_MODE,
- test_info->data,
- NULL);
-
- /* load data set */
- data_filename = g_strconcat (test_info->data, ".ttl", NULL);
- tracker_data_begin_transaction ();
- tracker_turtle_process (data_filename, NULL, consume_triple_storer, NULL);
- tracker_data_commit_transaction ();
-
- query_filename = g_strconcat (test_info->test_name, ".rq", NULL);
- g_file_get_contents (query_filename, &query, NULL, &error);
- g_assert (error == NULL);
-
- results_filename = g_strconcat (test_info->test_name, ".out", NULL);
- g_file_get_contents (results_filename, &results, NULL, &error);
- g_assert (error == NULL);
-
- /* perform actual query */
-
- result_set = tracker_data_query_sparql (query, &error);
- g_assert (error == NULL);
-
- /* compare results with reference output */
-
- test_results = g_string_new ("");
-
- if (result_set) {
- gboolean valid = TRUE;
- guint col_count;
- gint col;
+ /* fork as tracker-fts can only be initialized once per process (GType in loadable module) */
+ if (g_test_trap_fork (0, 0)) {
+ int exitcode;
+ GError *error;
+ gchar *data_filename;
+ gchar *query, *query_filename;
+ gchar *results, *results_filename;
+ TrackerDBResultSet *result_set;
+ GString *test_results;
+
+ exitcode = 0;
+ error = NULL;
+
+ /* initialization */
+ tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX | TRACKER_DB_MANAGER_TEST_MODE,
+ test_info->data,
+ NULL);
+
+ /* load data set */
+ data_filename = g_strconcat (test_info->data, ".ttl", NULL);
+ tracker_data_begin_transaction ();
+ tracker_turtle_process (data_filename, NULL, consume_triple_storer, NULL);
+ tracker_data_commit_transaction ();
+
+ query_filename = g_strconcat (test_info->test_name, ".rq", NULL);
+ g_file_get_contents (query_filename, &query, NULL, &error);
+ g_assert (error == NULL);
- col_count = tracker_db_result_set_get_n_columns (result_set);
+ results_filename = g_strconcat (test_info->test_name, ".out", NULL);
+ g_file_get_contents (results_filename, &results, NULL, &error);
+ g_assert (error == NULL);
- while (valid) {
- for (col = 0; col < col_count; col++) {
- GValue value = { 0 };
+ /* perform actual query */
- _tracker_db_result_set_get_value (result_set, col, &value);
+ result_set = tracker_data_query_sparql (query, &error);
+ g_assert (error == NULL);
- switch (G_VALUE_TYPE (&value)) {
- case G_TYPE_INT:
- g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&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;
+ /* compare results with reference output */
+
+ test_results = g_string_new ("");
+
+ 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_INT:
+ g_string_append_printf (test_results, "\"%d\"", g_value_get_int (&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");
+
+ valid = tracker_db_result_set_iter_next (result_set);
}
- g_string_append (test_results, "\n");
+ g_object_unref (result_set);
+ }
- valid = tracker_db_result_set_iter_next (result_set);
+ if (strcmp (results, test_results->str)) {
+ /* print result difference */
+ gchar *quoted_results;
+ gchar *command_line;
+ gchar *quoted_command_line;
+ gchar *shell;
+ gchar *diff;
+
+ quoted_results = g_shell_quote (test_results->str);
+ command_line = g_strdup_printf ("echo -n %s | diff -u %s -", quoted_results, results_filename);
+ quoted_command_line = g_shell_quote (command_line);
+ shell = g_strdup_printf ("sh -c %s", quoted_command_line);
+ g_spawn_command_line_sync (shell, &diff, NULL, NULL, &error);
+ g_assert (error == NULL);
+
+ g_error ("%s", diff);
+
+ g_free (quoted_results);
+ g_free (command_line);
+ g_free (quoted_command_line);
+ g_free (shell);
+ g_free (diff);
+
+ exitcode = 1;
}
- g_object_unref (result_set);
- }
+ /* cleanup */
- if (strcmp (results, test_results->str)) {
- /* print result difference */
- gchar *quoted_results;
- gchar *command_line;
- gchar *quoted_command_line;
- gchar *shell;
- gchar *diff;
-
- quoted_results = g_shell_quote (test_results->str);
- command_line = g_strdup_printf ("echo -n %s | diff -u %s -", quoted_results, results_filename);
- quoted_command_line = g_shell_quote (command_line);
- shell = g_strdup_printf ("sh -c %s", quoted_command_line);
- g_spawn_command_line_sync (shell, &diff, NULL, NULL, &error);
- g_assert (error == NULL);
+ g_free (data_filename);
+ g_free (query_filename);
+ g_free (query);
+ g_free (results_filename);
+ g_free (results);
+ g_string_free (test_results, TRUE);
- g_error ("%s", diff);
+ tracker_data_manager_shutdown ();
- g_free (quoted_results);
- g_free (command_line);
- g_free (quoted_command_line);
- g_free (shell);
- g_free (diff);
+ exit (exitcode);
}
- /* cleanup */
-
- g_free (data_filename);
- g_free (query_filename);
- g_free (query);
- g_free (results_filename);
- g_free (results);
- g_string_free (test_results, TRUE);
-
- tracker_data_manager_shutdown ();
+ g_test_trap_assert_passed ();
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]