[tracker/deprecated-g-test-trap-fork] WIP



commit cdacda94c1afff4f89b82e46119e444d30881d12
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Jan 17 18:17:05 2014 +0000

    WIP
    
    Just libtracker-common/dbus* to do.

 configure.ac                                      |    2 +-
 tests/libtracker-common/tracker-date-time-test.c  |   23 ++-
 tests/libtracker-common/tracker-dbus-test.c       |  216 ++++-----------------
 tests/libtracker-common/tracker-type-utils-test.c |  125 ++++++++-----
 tests/libtracker-extract/tracker-test-utils.c     |   29 ++-
 tests/libtracker-extract/tracker-test-xmp.c       |   29 ++-
 tests/libtracker-sparql/tracker-test.c            |   63 +++++--
 tests/tracker-steroids/tracker-test.c             |   27 +++-
 8 files changed, 257 insertions(+), 257 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5c3730b..a8d3175 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,7 +162,7 @@ PYTHON_REQUIRED=2.6
 
 # Library required versions
 DBUS_REQUIRED=1.3.1
-GLIB_REQUIRED=2.35.1
+GLIB_REQUIRED=2.38.0
 PANGO_REQUIRED=1.0.0
 GTK_REQUIRED=3.0.0
 LIBXML2_REQUIRED=2.6
diff --git a/tests/libtracker-common/tracker-date-time-test.c 
b/tests/libtracker-common/tracker-date-time-test.c
index d1b34b2..81ae1d7 100644
--- a/tests/libtracker-common/tracker-date-time-test.c
+++ b/tests/libtracker-common/tracker-date-time-test.c
@@ -33,6 +33,20 @@
 #endif
 
 static void
+test_string_to_date_failures_subprocess ()
+{
+       tracker_string_to_date (NULL, NULL, NULL);
+}
+
+static void
+test_string_to_date_failures ()
+{
+       g_test_trap_subprocess ("/libtracker-common/date-time/string_to_date_failures/subprocess", 0, 0);
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*'date_string' failed*");
+}
+
+static void
 test_string_to_date (void)
 {
        GDate     *expected;
@@ -69,11 +83,6 @@ test_string_to_date (void)
        g_assert_cmpint (g_date_get_day (expected), ==, g_date_get_day (result));
        g_assert_cmpint (g_date_get_month (expected), ==, g_date_get_month (result));
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               result_time_t = tracker_string_to_date (NULL, NULL, NULL);
-       }
-       g_test_trap_assert_failed ();
-
        result_time_t = tracker_string_to_date ("", NULL, &error);
        g_assert_cmpint (result_time_t, ==, -1);
        g_assert_error (error, TRACKER_DATE_ERROR, TRACKER_DATE_ERROR_INVALID_ISO8601);
@@ -231,6 +240,10 @@ main (gint argc, gchar **argv)
                          test_date_to_string);
         g_test_add_func ("/libtracker-common/date-time/string_to_date",
                          test_string_to_date);
+        g_test_add_func ("/libtracker-common/date-time/string_to_date_failures",
+                         test_string_to_date_failures);
+        g_test_add_func ("/libtracker-common/date-time/string_to_date_failures/subprocess",
+                         test_string_to_date_failures_subprocess);
         g_test_add_func ("/libtracker-common/date-time/get_set",
                          test_date_time_get_set);
         g_test_add_func ("/libtracker-common/date-time/from_string",
diff --git a/tests/libtracker-common/tracker-dbus-test.c b/tests/libtracker-common/tracker-dbus-test.c
index 8a6299a..c9d8879 100644
--- a/tests/libtracker-common/tracker-dbus-test.c
+++ b/tests/libtracker-common/tracker-dbus-test.c
@@ -43,13 +43,12 @@ log_handler (const gchar    *domain,
                g_print ("%s\n", message);
 }
 
-static void
-slist_to_strv (gboolean utf8)
+static inline GSList *
+slist_to_strv_get_source (gint     strings,
+                          gboolean utf8)
 {
        GSList *input = NULL;
-       gint    i;
-       gchar **input_as_strv;
-       gint    strings = 5;
+       gint i;
 
        for (i = 0; i < strings; i++) {
                if (utf8) {
@@ -58,54 +57,56 @@ slist_to_strv (gboolean utf8)
                        input = g_slist_prepend (input, g_strdup (tracker_test_helpers_get_nonutf8 ()));
                }
        }
-       g_assert_cmpint (g_slist_length (input), ==, strings);
 
-       if (utf8) {
-               input_as_strv = tracker_dbus_slist_to_strv (input);
+       return input;
+}
 
-               g_assert_cmpint (g_strv_length (input_as_strv), ==, (utf8 ? strings : 0));
-               g_strfreev (input_as_strv);
-       } else {
-               if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-                       g_log_set_default_handler (log_handler, NULL);
-                       input_as_strv = tracker_dbus_slist_to_strv (input);
-                       g_strfreev (input_as_strv);
-               }
-               /* Error message:
-                *   Could not add string:'/invalid/file/\xe4\xf6\xe590808.' to GStrv, invalid UTF-8
-                */
-               g_test_trap_assert_stderr ("*Could not add string:*");
-       }
+static void
+test_slist_to_strv_failures_subprocess (void)
+{
+       GSList *input;
+       gchar **input_as_strv;
+
+       input = slist_to_strv_get_source (5, TRUE);
+
+       g_log_set_default_handler (log_handler, NULL);
+       input_as_strv = tracker_dbus_slist_to_strv (input);
+       g_strfreev (input_as_strv);
 
        g_slist_foreach (input, (GFunc) g_free, NULL);
        g_slist_free (input);
 }
 
 static void
-test_slist_to_strv (void)
+test_slist_to_strv_failures (void)
 {
-       slist_to_strv (TRUE);
-}
+       g_test_trap_subprocess ("", 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
 
-#if 0
+       /* Error message:
+        *   Could not add string:'/invalid/file/\xe4\xf6\xe590808.' to GStrv, invalid UTF-8
+        */
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*Could not add string:*");
+}
 
 static void
-test_slist_to_strv_nonutf8 (void)
+test_slist_to_strv (void)
 {
-       slist_to_strv (FALSE);
-}
+       GSList *input;
+       gchar **input_as_strv;
+       gint strings = 5;
 
-#endif
+       input = slist_to_strv_get_source (strings, FALSE);
+       g_assert_cmpint (g_slist_length (input), ==, strings);
 
-#if 0
+       input_as_strv = tracker_dbus_slist_to_strv (input);
 
-static void
-test_async_queue_to_strv_nonutf8 (void)
-{
-       async_queue_to_strv (FALSE);
-}
+       g_assert_cmpint (g_strv_length (input_as_strv), ==, strings);
+       g_strfreev (input_as_strv);
 
-#endif
+       g_slist_foreach (input, (GFunc) g_free, NULL);
+       g_slist_free (input);
+}
 
 static void
 test_dbus_request_failed (void)
@@ -174,145 +175,6 @@ test_dbus_request ()
        g_test_trap_assert_passed ();
        g_test_trap_assert_stdout ("*Success*");
 }
-#if 0
-static void
-test_dbus_request_client_lookup ()
-{
-       TrackerDBusRequest *request;
-
-       tracker_dbus_enable_client_lookup (TRUE);
-
-
-       /* Checking the logging output */
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-               g_log_set_default_handler (log_handler, NULL);
-               request = tracker_dbus_request_begin ("tracker-dbus-test.c",
-                                                     "Test request (%s))",
-                                                     "--TestNewOK--");
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-       g_test_trap_assert_stdout ("*TestNewOK*");
-       g_test_trap_assert_stdout ("*lt-tracker-dbus*");
-
-       request = tracker_dbus_request_begin ("tracker-dbus-test.c",
-                                             "Test request (%s))",
-                                             "--TestNewOK--");
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               g_log_set_default_handler (log_handler, NULL);
-               tracker_dbus_request_comment (request,
-                                             "Well (%s)",
-                                             "--TestCommentOK--");
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-       g_test_trap_assert_stderr ("*TestCommentOK*");
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-               g_log_set_default_handler (log_handler, NULL);
-               tracker_dbus_request_info (request,
-                                          "Test info %s",
-                                          "--TestInfoOK--");
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-       g_test_trap_assert_stdout ("*TestInfoOK*");
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-               g_log_set_default_handler (log_handler, NULL);
-               tracker_dbus_request_debug (request,
-                                           "Test debug %s",
-                                           "--TestDebugOK--");
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-       g_test_trap_assert_stdout ("*TestDebugOK*");
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT)) {
-               g_log_set_default_handler (log_handler, NULL);
-               tracker_dbus_request_end (request, NULL);
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-       g_test_trap_assert_stdout ("*Success*");
-
-       /* Force client shutdown */
-       tracker_dbus_enable_client_lookup (FALSE);
-}
-
-static void
-test_dbus_request_client_lookup_monothread ()
-{
-       /* Run everything in the same fork to check the clients_shutdown code */
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) {
-               TrackerDBusRequest *request;
-
-               g_log_set_default_handler (log_handler, NULL);
-
-               tracker_dbus_enable_client_lookup (TRUE);
-               request = tracker_dbus_request_begin ("tracker-dbus-test.c",
-                                                     "Test request (%s))",
-                                                     "--TestNewOK--");
-               tracker_dbus_request_comment (request,
-                                             "Well (%s)",
-                                             "--TestCommentOK--");
-/*
-               tracker_dbus_request_end (request, NULL,
-                                         "--TestFailedOK--");
-               tracker_quark = tracker_dbus_error_quark ();
-               error = g_error_new (tracker_quark, -1, "test_using_g_error");
-               tracker_dbus_request_end (tracker_quark, error);
-*/
-
-               tracker_dbus_request_end (request, NULL);
-               /* Force client shutdown */
-               tracker_dbus_enable_client_lookup (FALSE);
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-}
-
-static void
-test_dbus_request_failed_coverage ()
-{
-       /* Repeat the failed test case in one thread to get coverage */
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) {
-               GQuark tracker_quark;
-               GError *error = NULL;
-               TrackerDBusRequest *request;
-
-               g_log_set_default_handler (log_handler, NULL);
-
-               tracker_dbus_enable_client_lookup (TRUE);
-
-               /* Using GError */
-               request = tracker_dbus_request_begin ("tracker-dbus-test.c",
-                                                     "Test request (%s))",
-                                                     "--TestNewOK--");
-               tracker_quark = tracker_dbus_error_quark ();
-               error = g_error_new (tracker_quark, -1, "test_using_g_error");
-               tracker_dbus_request_end (request, error);
-
-               request = tracker_dbus_request_begin ("tracker-dbus-test.c",
-                                                     "Test request (%s))",
-                                                     "--TestNewOK--");
-               tracker_dbus_request_end (request, NULL);
-
-               /* Force client shutdown */
-               tracker_dbus_enable_client_lookup (FALSE);
-               exit (0);
-       }
-
-       g_test_trap_assert_passed ();
-}
-#endif
 
 int
 main (int argc, char **argv) {
@@ -332,6 +194,10 @@ main (int argc, char **argv) {
 
        g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_ok",
                         test_slist_to_strv);
+       g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_failures",
+                        test_slist_to_strv_failures);
+       g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_failures/subprocess",
+                        test_slist_to_strv_failures_subprocess);
        g_test_add_func ("/libtracker-common/tracker-dbus/request",
                         test_dbus_request);
 /* port to gdbus first
diff --git a/tests/libtracker-common/tracker-type-utils-test.c 
b/tests/libtracker-common/tracker-type-utils-test.c
index 4eef837..1f9559b 100644
--- a/tests/libtracker-common/tracker-type-utils-test.c
+++ b/tests/libtracker-common/tracker-type-utils-test.c
@@ -103,6 +103,32 @@ test_guint32_to_string (void)
 }
 
 static void
+test_string_to_uint_failures_subprocess_1 (void)
+{
+       guint num = 10;
+
+       tracker_string_to_uint (NULL, &num);
+}
+
+static void
+test_string_to_uint_failures_subprocess_2 (void)
+{
+       tracker_string_to_uint ("199", NULL);
+}
+
+static void
+test_string_to_uint_failures (void)
+{
+       g_test_trap_subprocess ("/libtracker-common/tracker-type-utils/string_to_uint_failures/subprocess/1", 
0, 0);
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*assertion 's != NULL' failed*");
+
+       g_test_trap_subprocess ("/libtracker-common/tracker-type-utils/string_to_uint_failures/subprocess/2", 
0, 0);
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*assertion 'value != NULL' failed*");
+}
+
+static void
 test_string_to_uint (void)
 {
        guint num_result, rc;
@@ -112,28 +138,31 @@ test_string_to_uint (void)
        g_assert (rc);
        g_assert_cmpint (num_result, ==, 10);
 
+       rc = tracker_string_to_uint ("i am not a number", &num_result);
+       g_assert (!rc);
+       g_assert_cmpint (rc, ==, 0);
+}
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               rc = tracker_string_to_uint (NULL, &num_result);
-       }
-       g_test_trap_assert_failed ();
+static void
+test_string_in_string_list_failures_subprocess (void)
+{
+       const gchar *complete = "This is an extract of text with different terms an props like Audio:Title 
...";
+       gchar **pieces;
 
-       /* ???? FIXME */
-       rc = tracker_string_to_uint ("-20", &num_result);
+       pieces = g_strsplit (complete, " ", -1);
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               tracker_string_to_uint (NULL, &num_result);
-       }
-       g_test_trap_assert_failed ();
+       g_assert_cmpint (tracker_string_in_string_list (NULL, pieces), ==, -1);
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               tracker_string_to_uint ("199", NULL);
-       }
-       g_test_trap_assert_failed ();
+       g_strfreev (pieces);
+}
 
-       rc = tracker_string_to_uint ("i am not a number", &num_result);
-       g_assert (!rc);
-       g_assert_cmpint (rc, ==, 0);
+static void
+test_string_in_string_list_failures (void)
+{
+
+       g_test_trap_subprocess 
("/libtracker-common/tracker-type-utils/string_in_string_list_failures/subprocess", 0, 0);
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*assertion 'str != NULL' failed*");
 }
 
 static void
@@ -147,15 +176,7 @@ test_string_in_string_list (void)
        g_assert_cmpint (tracker_string_in_string_list ("is", pieces), ==, 1);
        g_assert_cmpint (tracker_string_in_string_list ("Audio:Title", pieces), ==, 12);
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               g_assert_cmpint (tracker_string_in_string_list (NULL, pieces), ==, -1);
-       }
-       g_test_trap_assert_failed ();
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               g_assert_cmpint (tracker_string_in_string_list ("terms", NULL), ==, -1);
-       }
-       g_test_trap_assert_failed ();
+       g_assert_cmpint (tracker_string_in_string_list ("terms", NULL), ==, -1);
 }
 
 static void
@@ -198,12 +219,9 @@ test_gslist_to_string_list (void)
 
        g_strfreev (result);
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               result = tracker_gslist_to_string_list (NULL);
-               g_strfreev (result);
-       }
-
-       g_test_trap_assert_failed ();
+       result = tracker_gslist_to_string_list (NULL);
+       g_assert (result != NULL);
+       g_strfreev (result);
 }
 
 static void
@@ -253,12 +271,8 @@ test_string_list_to_string (void)
        g_assert_cmpstr ("one_two_three", ==, result);
        g_free (result);
 
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               result = tracker_string_list_to_string (NULL, 6, 'x');
-               g_free (result);
-       }
-       g_test_trap_assert_failed ();
+       result = tracker_string_list_to_string (NULL, 6, 'x');
+       g_assert (result == NULL);
 
        result = tracker_string_list_to_string (pieces, -1, ' ');
        g_assert_cmpstr (input, ==, result);
@@ -283,6 +297,20 @@ test_string_to_string_list (void)
 }
 
 static void
+test_boolean_as_text_to_number_failures_subprocess (void)
+{
+       tracker_string_boolean_to_string_gint (NULL);
+}
+
+static void
+test_boolean_as_text_to_number_failures (void)
+{
+       g_test_trap_subprocess 
("/libtracker-common/tracker-type-utils/boolean_as_text_to_number_failures/subprocess", 0, 0);
+       g_test_trap_assert_failed ();
+       g_test_trap_assert_stderr ("*assertion 'value != NULL' failed*");
+}
+
+static void
 test_boolean_as_text_to_number (void)
 {
        gchar *result;
@@ -326,13 +354,6 @@ test_boolean_as_text_to_number (void)
        result = tracker_string_boolean_to_string_gint ("Other invalid value");
         g_assert_cmpstr (result, ==, "Other invalid value");
        g_free (result);
-
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               result = tracker_string_boolean_to_string_gint (NULL);
-               g_free (result);
-       }
-       g_test_trap_assert_failed ();
 }
 
 static void
@@ -401,6 +422,10 @@ main (int argc, char **argv)
 
        g_test_add_func ("/libtracker-common/tracker-type-utils/boolean_as_text_to_number",
                         test_boolean_as_text_to_number);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/boolean_as_text_to_number_failures",
+                        test_boolean_as_text_to_number_failures);
+       g_test_add_func 
("/libtracker-common/tracker-type-utils/boolean_as_text_to_number_failures/subprocess",
+                        test_boolean_as_text_to_number_failures_subprocess);
        g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_as_list",
                         test_string_list_to_string);
        g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_as_list",
@@ -409,12 +434,22 @@ main (int argc, char **argv)
                         test_gslist_to_string_list);
        g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list",
                         test_string_in_string_list);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list_failures",
+                        test_string_in_string_list_failures);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list_failures/subprocess",
+                        test_string_in_string_list_failures_subprocess);
         g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_gslist",
                          test_string_in_gslist);
         g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_to_gslist",
                          test_string_list_to_gslist);
        g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_uint",
                         test_string_to_uint);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_uint_failures",
+                        test_string_to_uint_failures);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_uint_failures/subprocess/1",
+                        test_string_to_uint_failures_subprocess_1);
+       g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_uint_failures/subprocess/2",
+                        test_string_to_uint_failures_subprocess_2);
        g_test_add_func ("/libtracker-common/tracker-type-utils/guint32_to_string",
                         test_guint32_to_string);
        g_test_add_func ("/libtracker-common/tracker-type-utils/gint32_to_string",
diff --git a/tests/libtracker-extract/tracker-test-utils.c b/tests/libtracker-extract/tracker-test-utils.c
index 0839ab9..fce4643 100644
--- a/tests/libtracker-extract/tracker-test-utils.c
+++ b/tests/libtracker-extract/tracker-test-utils.c
@@ -29,6 +29,24 @@
 #include <libtracker-extract/tracker-extract.h>
 
 static void
+test_guess_date_failures_subprocess ()
+{
+       gchar *result;
+
+       result = tracker_date_guess (NULL);
+       g_free (result);
+}
+
+static void
+test_guess_date_failures ()
+{
+       g_test_trap_subprocess ("/libtracker-extract/tracker-utils/guess_date_failures/subprocess", 0, 
G_TEST_SUBPROCESS_INHERIT_STDERR);
+       g_test_trap_assert_passed ();
+
+       /* Should be NO output when using NULL with tracker_date_guess() */
+}
+
+static void
 test_guess_date (void)
 {
        gchar *result;
@@ -83,13 +101,6 @@ test_guess_date (void)
         result = tracker_date_guess ("2010-03-18T01:02:03.100");
         g_assert_cmpstr (result, ==, "2010-03-18T01:02:03.100");
         g_free (result);
-
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               result = tracker_date_guess (NULL);
-               g_free (result);
-       }
-
-       g_test_trap_assert_failed ();
 }
 
 static void
@@ -274,6 +285,10 @@ main (int argc, char **argv)
 
        g_test_add_func ("/libtracker-extract/tracker-utils/guess_date",
                         test_guess_date);
+       g_test_add_func ("/libtracker-extract/tracker-utils/guess_date_failures",
+                        test_guess_date_failures);
+       g_test_add_func ("/libtracker-extract/tracker-utils/guess_date_failures/subprocess",
+                        test_guess_date_failures_subprocess);
         g_test_add_func ("/libtracker-extract/tracker-utils/text-validate-utf8",
                          test_text_validate_utf8);
         g_test_add_func ("/libtracker-extract/tracker-utils/date_to_iso8601",
diff --git a/tests/libtracker-extract/tracker-test-xmp.c b/tests/libtracker-extract/tracker-test-xmp.c
index 89148fb..d8a2708 100644
--- a/tests/libtracker-extract/tracker-test-xmp.c
+++ b/tests/libtracker-extract/tracker-test-xmp.c
@@ -180,19 +180,29 @@ get_example_expected (void)
 };
 
 static void
-test_parsing_xmp (void)
+test_parsing_xmp_invalid_file_subprocess (void)
 {
        TrackerXmpData *data;
-       TrackerXmpData *expected;
 
-       if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
-               data = tracker_xmp_new (BROKEN_XMP, strlen (BROKEN_XMP), "test://file");
-               g_assert (data != NULL);
+       data = tracker_xmp_new (BROKEN_XMP, strlen (BROKEN_XMP), "test://file");
+       g_assert (data != NULL);
 
-               tracker_xmp_free (data);
-       }
+       tracker_xmp_free (data);
+}
 
+static void
+test_parsing_xmp_invalid_file (void)
+{
+       g_test_trap_subprocess ("/libtracker-extract/tracker-xmp/parsing_xmp_invalid_file/subprocess", 0, 0);
+       g_test_trap_assert_passed ();
        g_test_trap_assert_stderr ("*parsing failure*");
+}
+
+static void
+test_parsing_xmp (void)
+{
+       TrackerXmpData *data;
+       TrackerXmpData *expected;
 
        data = tracker_xmp_new (EXAMPLE_XMP, strlen (EXAMPLE_XMP), "test://file");
        expected = get_example_expected ();
@@ -606,6 +616,11 @@ main (int    argc,
        g_test_add_func ("/libtracker-extract/tracker-xmp/parsing_xmp",
                         test_parsing_xmp);
 
+       g_test_add_func ("/libtracker-extract/tracker-xmp/parsing_xmp_invalid_file",
+                        test_parsing_xmp_invalid_file);
+       g_test_add_func ("/libtracker-extract/tracker-xmp/parsing_xmp_invalid_file/subprocess",
+                        test_parsing_xmp_invalid_file_subprocess);
+
        g_test_add_func ("/libtracker-extract/tracker-xmp/metering-mode",
                         test_xmp_metering_mode);
 
diff --git a/tests/libtracker-sparql/tracker-test.c b/tests/libtracker-sparql/tracker-test.c
index ee0dbad..5784fb4 100644
--- a/tests/libtracker-sparql/tracker-test.c
+++ b/tests/libtracker-sparql/tracker-test.c
@@ -21,6 +21,8 @@
 
 #include <locale.h>
 
+#include <glib-object.h>
+
 #include <libtracker-sparql/tracker-sparql.h>
 
 typedef struct {
@@ -295,31 +297,64 @@ test_tracker_sparql_nb237150_cb (GObject      *source_object,
                                  GAsyncResult *result,
                                  gpointer      user_data)
 {
+       TrackerSparqlConnection *connection;
+       GError *error = NULL;
+       static gboolean had_1 = FALSE;
+       static gboolean had_2 = FALSE;
+
+       connection = tracker_sparql_connection_get_finish (result, &error);
+       g_assert_no_error (error);
+       g_assert (connection != NULL);
+
        /* Not actually worried about this being called */
        g_print ("Called back for #%d\n", GPOINTER_TO_INT(user_data));
+
+       if (GPOINTER_TO_INT(user_data) == 1)
+               had_1 = TRUE;
+       if (GPOINTER_TO_INT(user_data) == 2)
+               had_2 = TRUE;
+
+       if (had_1 && had_2) {
+               g_print ("Called back ALL\n");
+               g_main_loop_quit (main_loop);
+       }
 }
 
 static void
-test_tracker_sparql_nb237150 (void)
+test_tracker_sparql_nb237150_subprocess (void)
 {
-       /* Test NB#237150 - Second tracker_sparql_connection_get_async never returns */
-       if (g_test_trap_fork (G_USEC_PER_SEC * 2, G_TEST_TRAP_SILENCE_STDOUT)) {
-               g_print ("\n");
-               g_print ("Calling #1 - tracker_sparql_connection_get_async()\n");
-               tracker_sparql_connection_get_async (NULL, test_tracker_sparql_nb237150_cb, 
GINT_TO_POINTER(1));
+       g_print ("\n");
+       g_print ("Calling #1 - tracker_sparql_connection_get_async()\n");
+       tracker_sparql_connection_get_async (NULL, test_tracker_sparql_nb237150_cb, GINT_TO_POINTER(1));
 
-               g_print ("Calling #2 - tracker_sparql_connection_get_async()\n");
-               tracker_sparql_connection_get_async (NULL, test_tracker_sparql_nb237150_cb, 
GINT_TO_POINTER(2));
+       g_print ("Calling #2 - tracker_sparql_connection_get_async()\n");
+       tracker_sparql_connection_get_async (NULL, test_tracker_sparql_nb237150_cb, GINT_TO_POINTER(2));
 
-               g_print ("Calling both finished\n");
+       g_print ("Calling both finished\n");
+}
 
-               exit (0); /* successful test run */
-       }
+static void
+test_tracker_sparql_nb237150 (void)
+{
+       /* Test NB#237150 - Second tracker_sparql_connection_get_async
+        * never returns
+        */
+       g_test_trap_subprocess ("/libtracker-sparql/tracker/nb237150/subprocess",
+                               G_USEC_PER_SEC * 2,
+                               G_TEST_SUBPROCESS_INHERIT_STDOUT);
 
        g_test_trap_assert_passed ();
+
+       /* Check we called the functions in the test */
        g_test_trap_assert_stdout ("*Calling #1*");
        g_test_trap_assert_stdout ("*Calling #2*");
        g_test_trap_assert_stdout ("*Calling both finished*");
+
+       /* Check the callbacks from the functions we called were
+        * called in the test */
+       g_test_trap_assert_stdout ("*Called back for #1*");
+       g_test_trap_assert_stdout ("*Called back for #2*");
+       g_test_trap_assert_stdout ("*Called back ALL*");
 }
 
 static void
@@ -371,9 +406,11 @@ main (gint argc, gchar **argv)
        /* NOTE: this first test must come BEFORE any others because
         * connections are cached by libtracker-sparql.
         */
-       g_test_add_func ("/libtracker-sparql/tracker/test_tracker_sparql_nb237150",
+       g_test_add_func ("/libtracker-sparql/tracker/nb237150",
                         test_tracker_sparql_nb237150);
-       g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_string", 
+       g_test_add_func ("/libtracker-sparql/tracker/nb237150/subprocess",
+                        test_tracker_sparql_nb237150_subprocess);
+       g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_string",
                         test_tracker_sparql_escape_string);
        g_test_add_func ("/libtracker-sparql/tracker/tracker_sparql_escape_uri_vprintf",
                         test_tracker_sparql_escape_uri_vprintf);
diff --git a/tests/tracker-steroids/tracker-test.c b/tests/tracker-steroids/tracker-test.c
index b246c4a..8eada53 100644
--- a/tests/tracker-steroids/tracker-test.c
+++ b/tests/tracker-steroids/tracker-test.c
@@ -209,6 +209,26 @@ test_tracker_sparql_query_iterate_error ()
 
 /* Runs a query returning an empty set */
 static void
+test_tracker_sparql_query_iterate_empty_subprocess ()
+{
+       TrackerSparqlCursor *cursor;
+       GError *error = NULL;
+       const gchar *query = "SELECT ?r WHERE {?r a nfo:FileDataObject; nao:identifier 
\"thisannotationdoesnotexist\"}";
+
+       cursor = tracker_sparql_connection_query (connection, query, NULL, &error);
+
+       tracker_sparql_cursor_next (cursor, NULL, NULL);
+
+       /* Testing we fail with this error:
+        *
+        *   Tracker-CRITICAL **:
+        *   tracker_bus_fd_cursor_real_get_string: assertion '(_tmp0_
+        *   < _tmp2_) && (_tmp3_ != NULL)' failed
+        */
+       tracker_sparql_cursor_get_string (cursor, 0, NULL);
+}
+
+static void
 test_tracker_sparql_query_iterate_empty ()
 {
        TrackerSparqlCursor *cursor;
@@ -224,10 +244,8 @@ test_tracker_sparql_query_iterate_empty ()
        /* 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);
-       }
+
+       g_test_trap_subprocess ("/steroids/tracker/tracker_sparql_query_iterate_empty/subprocess", 0, 0);
        g_test_trap_assert_failed ();
 
        g_object_unref (cursor);
@@ -675,6 +693,7 @@ main (gint argc, gchar **argv)
        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_largerow", 
test_tracker_sparql_query_iterate_largerow);
        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_error", 
test_tracker_sparql_query_iterate_error);
        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_empty", 
test_tracker_sparql_query_iterate_empty);
+       g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_empty/subprocess", 
test_tracker_sparql_query_iterate_empty_subprocess);
        g_test_add_func ("/steroids/tracker/tracker_sparql_query_iterate_sigpipe", 
test_tracker_sparql_query_iterate_sigpipe);
        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);


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