[tracker] tests/libtracker-data: Unit test for more than one regex query
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tests/libtracker-data: Unit test for more than one regex query
- Date: Wed, 7 Apr 2010 12:24:51 +0000 (UTC)
commit 8856e1d43a5a5654bbb81e9eecf84a0b2aa93998
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Apr 7 14:23:29 2010 +0200
tests/libtracker-data: Unit test for more than one regex query
tests/libtracker-data/regex/regex-data-01.ttl | 5 +
.../regex/regex-query-001.extra.out | 1 +
.../libtracker-data/regex/regex-query-001.extra.rq | 8 +
tests/libtracker-data/tracker-sparql-test.c | 178 ++++++++++++--------
4 files changed, 118 insertions(+), 74 deletions(-)
---
diff --git a/tests/libtracker-data/regex/regex-data-01.ttl b/tests/libtracker-data/regex/regex-data-01.ttl
index 2240fc4..76e620b 100755
--- a/tests/libtracker-data/regex/regex-data-01.ttl
+++ b/tests/libtracker-data/regex/regex-data-01.ttl
@@ -4,5 +4,10 @@
ex:foo a example:A .
+ex:bar a example:A .
+
ex:foo rdf:value "abcDEFghiJKL" , "ABCdefGHIjkl", "0123456789",
"http://example.com/literal" .
+
+ex:bar rdf:value "abcDRFghiJKL" , "ABCdrfGHIjkl", "0123456789",
+ "http://example.com/literal" .
diff --git a/tests/libtracker-data/regex/regex-query-001.extra.out b/tests/libtracker-data/regex/regex-query-001.extra.out
new file mode 100644
index 0000000..22292dd
--- /dev/null
+++ b/tests/libtracker-data/regex/regex-query-001.extra.out
@@ -0,0 +1 @@
+"ABCdrfGHIjkl"
diff --git a/tests/libtracker-data/regex/regex-query-001.extra.rq b/tests/libtracker-data/regex/regex-query-001.extra.rq
new file mode 100755
index 0000000..23f9c18
--- /dev/null
+++ b/tests/libtracker-data/regex/regex-query-001.extra.rq
@@ -0,0 +1,8 @@
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX ex: <http://example.com/#>
+
+SELECT ?val
+WHERE {
+ ex:bar rdf:value ?val .
+ FILTER regex(?val, "GHI")
+}
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 3344444..c4584aa 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -113,79 +113,15 @@ strstr_i (const char *a, const char *b)
}
static void
-test_sparql_query (gconstpointer test_data)
+check_result (TrackerDBResultSet *result_set,
+ const TestInfo *test_info,
+ const gchar *results_filename,
+ GError *error)
{
int (*comparer) (const char *a, const char *b);
- TrackerDBResultSet *result_set;
- const TestInfo *test_info;
- GError *error;
GString *test_results;
- gchar *data_filename;
- gchar *query, *query_filename;
- gchar *results, *results_filename;
- gchar *prefix, *data_prefix, *test_prefix;
- const gchar *test_schemas[2] = { NULL, NULL };
-
- error = NULL;
- test_info = test_data;
-
- /* initialization */
- prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL);
- data_prefix = g_build_filename (prefix, test_info->data, NULL);
- test_prefix = g_build_filename (prefix, test_info->test_name, NULL);
- g_free (prefix);
-
- test_schemas[0] = data_prefix;
- tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
- test_schemas,
- NULL, FALSE, NULL, NULL, NULL);
-
- /* data_path = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL); */
-
- /* load data set */
- data_filename = g_strconcat (data_prefix, ".ttl", NULL);
- if (g_file_test (data_filename, G_FILE_TEST_IS_REGULAR)) {
- tracker_data_begin_db_transaction ();
- tracker_turtle_reader_load (data_filename, &error);
- tracker_data_commit_db_transaction ();
- g_assert_no_error (error);
- } else {
- /* no .ttl available, assume .rq with SPARQL Update */
- gchar *data;
-
- g_free (data_filename);
-
- data_filename = g_strconcat (data_prefix, ".rq", NULL);
- g_file_get_contents (data_filename, &data, NULL, &error);
- g_assert_no_error (error);
-
- tracker_data_begin_db_transaction ();
- tracker_data_update_sparql (data, &error);
- tracker_data_commit_db_transaction ();
- if (test_info->expect_update_error) {
- g_assert (error != NULL);
- g_clear_error (&error);
- } else {
- g_assert_no_error (error);
- }
-
- g_free (data);
- }
-
- query_filename = g_strconcat (test_prefix, ".rq", NULL);
- g_file_get_contents (query_filename, &query, NULL, &error);
- g_assert_no_error (error);
-
- results_filename = g_strconcat (test_prefix, ".out", NULL);
- g_file_get_contents (results_filename, &results, NULL, &error);
- g_assert_no_error (error);
-
- g_free (data_prefix);
- g_free (test_prefix);
-
- /* perform actual query */
-
- result_set = tracker_data_query_sparql (query, &error);
+ gchar *results;
+ GError *nerror = NULL;
if (test_info->expect_query_error) {
comparer = strstr_i;
@@ -195,6 +131,10 @@ test_sparql_query (gconstpointer test_data)
g_assert_no_error (error);
}
+ g_file_get_contents (results_filename, &results, NULL, &nerror);
+ g_assert_no_error (nerror);
+ g_clear_error (&nerror);
+
/* compare results with reference output */
test_results = g_string_new ("");
@@ -236,8 +176,6 @@ test_sparql_query (gconstpointer test_data)
valid = tracker_db_result_set_iter_next (result_set);
}
-
- g_object_unref (result_set);
} else if (test_info->expect_query_error) {
g_string_append (test_results, error->message);
g_clear_error (&error);
@@ -267,14 +205,106 @@ test_sparql_query (gconstpointer test_data)
g_free (diff);
}
+ g_string_free (test_results, TRUE);
+ g_free (results);
+}
+
+static void
+test_sparql_query (gconstpointer test_data)
+{
+ TrackerDBResultSet *result_set;
+ const TestInfo *test_info;
+ GError *error;
+ gchar *data_filename;
+ gchar *query, *query_filename;
+ gchar *results_filename;
+ gchar *prefix, *data_prefix, *test_prefix;
+ const gchar *test_schemas[2] = { NULL, NULL };
+
+ error = NULL;
+ test_info = test_data;
+
+ /* initialization */
+ prefix = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL);
+ data_prefix = g_build_filename (prefix, test_info->data, NULL);
+ test_prefix = g_build_filename (prefix, test_info->test_name, NULL);
+ g_free (prefix);
+
+ test_schemas[0] = data_prefix;
+ tracker_data_manager_init (TRACKER_DB_MANAGER_FORCE_REINDEX,
+ test_schemas,
+ NULL, FALSE, NULL, NULL, NULL);
+
+ /* data_path = g_build_path (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "libtracker-data", NULL); */
+
+ /* load data set */
+ data_filename = g_strconcat (data_prefix, ".ttl", NULL);
+ if (g_file_test (data_filename, G_FILE_TEST_IS_REGULAR)) {
+ tracker_data_begin_db_transaction ();
+ tracker_turtle_reader_load (data_filename, &error);
+ tracker_data_commit_db_transaction ();
+ g_assert_no_error (error);
+ } else {
+ /* no .ttl available, assume .rq with SPARQL Update */
+ gchar *data;
+
+ g_free (data_filename);
+
+ data_filename = g_strconcat (data_prefix, ".rq", NULL);
+ g_file_get_contents (data_filename, &data, NULL, &error);
+ g_assert_no_error (error);
+
+ tracker_data_begin_db_transaction ();
+ tracker_data_update_sparql (data, &error);
+ tracker_data_commit_db_transaction ();
+ if (test_info->expect_update_error) {
+ g_assert (error != NULL);
+ g_clear_error (&error);
+ } else {
+ g_assert_no_error (error);
+ }
+
+ g_free (data);
+ }
+
+ query_filename = g_strconcat (test_prefix, ".rq", NULL);
+ g_file_get_contents (query_filename, &query, NULL, &error);
+ g_assert_no_error (error);
+
+ results_filename = g_strconcat (test_prefix, ".out", NULL);
+
+ /* perform actual query */
+
+ result_set = tracker_data_query_sparql (query, &error);
+
+ check_result (result_set, test_info, results_filename, error);
+
+ g_free (query_filename);
+ g_free (query);
+
+ query_filename = g_strconcat (test_prefix, ".extra.rq", NULL);
+ if (g_file_get_contents (query_filename, &query, NULL, NULL)) {
+ g_object_unref (result_set);
+ result_set = tracker_data_query_sparql (query, &error);
+ g_assert_no_error (error);
+ g_free (results_filename);
+ results_filename = g_strconcat (test_prefix, ".extra.out", NULL);
+ check_result (result_set, test_info, results_filename, error);
+ }
+
+ g_free (data_prefix);
+ g_free (test_prefix);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
/* 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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]