[tracker/dbus-fd-experiment-gio: 15/41] Add tests for Steroids/SparqlUpdateBlank
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/dbus-fd-experiment-gio: 15/41] Add tests for Steroids/SparqlUpdateBlank
- Date: Thu, 10 Jun 2010 22:53:28 +0000 (UTC)
commit fdc18b4f9506a2bb8b523cf9ccfda8e47b62e812
Author: Adrien Bustany <abustany gnome org>
Date: Thu Jun 3 13:00:19 2010 -0400
Add tests for Steroids/SparqlUpdateBlank
tests/tracker-steroids/tracker-test.c | 175 +++++++++++++++++++++++++++++++++
1 files changed, 175 insertions(+), 0 deletions(-)
---
diff --git a/tests/tracker-steroids/tracker-test.c b/tests/tracker-steroids/tracker-test.c
index 66250b4..11f18dd 100644
--- a/tests/tracker-steroids/tracker-test.c
+++ b/tests/tracker-steroids/tracker-test.c
@@ -59,6 +59,101 @@ insert_test_data ()
g_assert (!error);
}
+static void
+free_hash_table (GHashTable *hash, gpointer user_data)
+{
+ g_hash_table_unref (hash);
+}
+
+static void
+free_results_inner (GPtrArray *array, gpointer user_data)
+{
+ g_ptr_array_foreach (array, (GFunc)free_hash_table, NULL);
+ g_ptr_array_free (array, TRUE);
+}
+
+static void
+free_results (GPtrArray *results)
+{
+ g_ptr_array_foreach (results, (GFunc)free_results_inner, NULL);
+ g_ptr_array_free (results, TRUE);
+}
+
+/*
+ * I comment that part out because I don't know how anonymous node hashing
+ * works, but if we know two SparqlUpdate calls are going to return the same
+ * urns we could use those functions to compare the results between the normal
+ * and fast method. I wrote them before realizing I wouldn't know how to use
+ * them.
+ */
+/*
+static gboolean
+compare_hash_tables (GHashTable *h1, GHashTable *h2)
+{
+ GHashTableIter i1, i2;
+ gpointer k1, v1, k2, v2;
+
+ if (g_hash_table_size (h1) != g_hash_table_size (h2)) {
+ return FALSE;
+ }
+
+ g_hash_table_iter_init (&i1, h1);
+ g_hash_table_iter_init (&i2, h2);
+
+ while (g_hash_table_iter_next (&i1, &k1, &v1)) {
+ g_hash_table_iter_next (&i2, &k2, &v2);
+
+ if (g_strcmp0 (k1, k2)) {
+ return FALSE;
+ }
+
+ if (g_strcmp0 (v1, v2)) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+static gboolean
+compare_results (GPtrArray *r1, GPtrArray *r2)
+{
+ int i, j;
+
+ if (!r1 || !r2) {
+ return FALSE;
+ }
+
+ if (r1->len != r2->len) {
+ return FALSE;
+ }
+
+ for (i = 0; i < r1->len; i++) {
+ GPtrArray *inner1, *inner2;
+
+ inner1 = g_ptr_array_index (r1, i);
+ inner2 = g_ptr_array_index (r2, i);
+
+ if (inner1->len != inner2->len) {
+ return FALSE;
+ }
+
+ for (j = 0; j < inner1->len; j++) {
+ GHashTable *h1, *h2;
+
+ h1 = g_ptr_array_index (inner1, j);
+ h2 = g_ptr_array_index (inner2, j);
+
+ if (!compare_hash_tables (h1, h2)) {
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+*/
+
/* Runs the same query using the iterate and traditional interface, and compare
* the results */
static void
@@ -233,6 +328,82 @@ test_tracker_sparql_update_fast_error ()
return;
}
+static void
+test_tracker_sparql_update_blank_fast_small ()
+{
+ GError *error = NULL;
+ const gchar *query = "INSERT { _:x a nmo:Message }";
+ GPtrArray *results;
+
+ results = tracker_resources_sparql_update_blank_fast (client, query, &error);
+
+ g_assert (!error);
+ g_assert (results);
+
+ free_results (results);
+
+ return;
+}
+
+static void
+test_tracker_sparql_update_blank_fast_large ()
+{
+ GError *error = NULL;
+ const gchar *query_template = "INSERT { _:x a nmo:Message; nao:identifier \"%s\" }";
+ gchar *lotsOfA;
+ gchar *query;
+ GPtrArray *results;
+
+ lotsOfA = g_malloc (LONG_NAME_SIZE);
+ memset (lotsOfA, 'a', LONG_NAME_SIZE);
+
+ query = g_strdup_printf (query_template, lotsOfA);
+
+ results = tracker_resources_sparql_update_blank_fast (client, query, &error);
+
+ g_free (lotsOfA);
+ g_free (query);
+
+ g_assert (!error);
+ g_assert (results);
+
+ free_results (results);
+
+ return;
+}
+
+static void
+test_tracker_sparql_update_blank_fast_error ()
+{
+ GError *error = NULL;
+ const gchar *query = "blork blork blork";
+ GPtrArray *results;
+
+ results = tracker_resources_sparql_update_blank_fast (client, query, &error);
+
+ g_assert (error);
+ g_assert (!results);
+
+ return;
+}
+
+static void
+test_tracker_sparql_update_blank_fast_no_blanks ()
+{
+ GError *error = NULL;
+ const gchar *query = "INSERT { <urn:not_blank> a nmo:Message }";
+ GPtrArray *results;
+
+ results = tracker_resources_sparql_update_blank_fast (client, query, &error);
+
+ g_assert (!error);
+ g_assert (results);
+
+ free_results (results);
+
+ return;
+}
+
gint
main (gint argc, gchar **argv)
{
@@ -251,6 +422,10 @@ main (gint argc, gchar **argv)
g_test_add_func ("/steroids/tracker/tracker_sparql_update_fast_small", test_tracker_sparql_update_fast_small);
g_test_add_func ("/steroids/tracker/tracker_sparql_update_fast_large", test_tracker_sparql_update_fast_large);
g_test_add_func ("/steroids/tracker/tracker_sparql_update_fast_error", test_tracker_sparql_update_fast_error);
+ g_test_add_func ("/steroids/tracker/tracker_sparql_update_blank_fast_small", test_tracker_sparql_update_blank_fast_small);
+ g_test_add_func ("/steroids/tracker/tracker_sparql_update_blank_fast_large", test_tracker_sparql_update_blank_fast_large);
+ g_test_add_func ("/steroids/tracker/tracker_sparql_update_blank_fast_error", test_tracker_sparql_update_blank_fast_error);
+ g_test_add_func ("/steroids/tracker/tracker_sparql_update_blank_fast_no_blanks", test_tracker_sparql_update_blank_fast_no_blanks);
/* client is leaked */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]