summaryrefslogtreecommitdiff
path: root/tests/libtracker-common
diff options
context:
space:
mode:
authorMartyn Russell <martyn@lanedo.com>2014-01-17 18:17:05 +0000
committerMartyn Russell <martyn@lanedo.com>2014-01-17 18:53:57 +0000
commit4d206f76aae4a543057124c98793d0e815cdb6d7 (patch)
tree2fb8e7f175a26ba7cdc026473e08050e7de88fe9 /tests/libtracker-common
parent72dc5e49d412e8db153366777c2f61016d4b67d3 (diff)
downloadtracker-4d206f76aae4a543057124c98793d0e815cdb6d7.tar.gz
tests: Removed all cases of g_test_trap_fork() which has been deprecated.
Now we're using g_test_trap_subprocess() instead and that requires GLib 2.38. Tracker now depends on GLib 2.38.
Diffstat (limited to 'tests/libtracker-common')
-rw-r--r--tests/libtracker-common/tracker-date-time-test.c23
-rw-r--r--tests/libtracker-common/tracker-dbus-test.c286
-rw-r--r--tests/libtracker-common/tracker-type-utils-test.c125
3 files changed, 164 insertions, 270 deletions
diff --git a/tests/libtracker-common/tracker-date-time-test.c b/tests/libtracker-common/tracker-date-time-test.c
index d1b34b299..81ae1d70c 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 8a6299ab2..e9f25352f 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,261 +57,105 @@ 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);
-
- 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:*");
- }
- g_slist_foreach (input, (GFunc) g_free, NULL);
- g_slist_free (input);
+ return input;
}
static void
-test_slist_to_strv (void)
+test_slist_to_strv_failures_subprocess (void)
{
- slist_to_strv (TRUE);
-}
-
-#if 0
+ GSList *input;
+ gchar **input_as_strv;
-static void
-test_slist_to_strv_nonutf8 (void)
-{
- slist_to_strv (FALSE);
-}
+ input = slist_to_strv_get_source (5, FALSE);
-#endif
+ g_log_set_default_handler (log_handler, NULL);
+ input_as_strv = tracker_dbus_slist_to_strv (input);
+ g_assert_cmpint (g_strv_length (input_as_strv), ==, 0);
+ g_strfreev (input_as_strv);
-#if 0
+ g_slist_foreach (input, (GFunc) g_free, NULL);
+ g_slist_free (input);
+}
static void
-test_async_queue_to_strv_nonutf8 (void)
+test_slist_to_strv_failures (void)
{
- async_queue_to_strv (FALSE);
-}
+ g_test_trap_subprocess ("/libtracker-common/tracker-dbus/slist_to_strv_failures/subprocess", 0, 0);
-#endif
+ /* Error message:
+ * Could not add string:'/invalid/file/\xe4\xf6\xe590808.' to GStrv, invalid UTF-8
+ */
+ g_test_trap_assert_passed ();
+ g_test_trap_assert_stderr ("*Could not add string:*");
+}
static void
-test_dbus_request_failed (void)
+test_slist_to_strv (void)
{
- TrackerDBusRequest *request;
- GError *error = NULL;
+ GSList *input;
+ gchar **input_as_strv;
+ gint strings = 5;
- /* For some (unknown) reason, this calls don't appear in the
- * coverage evaluation. */
+ input = slist_to_strv_get_source (strings, TRUE);
+ g_assert_cmpint (g_slist_length (input), ==, strings);
- request = tracker_dbus_request_begin ("tracker-dbus-test.c",
- "%s()",
- __PRETTY_FUNCTION__);
+ input_as_strv = tracker_dbus_slist_to_strv (input);
- /* We have already the error and want only the log line */
- error = g_error_new (1000, -1, "The indexer founded an error");
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
- g_log_set_default_handler (log_handler, NULL);
- tracker_dbus_request_end (request, error);
- }
+ g_assert_cmpint (g_strv_length (input_as_strv), ==, strings);
+ g_strfreev (input_as_strv);
- g_test_trap_assert_stderr ("*The indexer founded an error*");
- g_error_free (error);
+ g_slist_foreach (input, (GFunc) g_free, NULL);
+ g_slist_free (input);
}
static void
-test_dbus_request ()
+test_dbus_request_subprocess (void)
{
TrackerDBusRequest *request;
+ GError *error = NULL;
tracker_dbus_enable_client_lookup (FALSE);
- /* 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_log_set_default_handler (log_handler, NULL);
+ /* New request case */
request = tracker_dbus_request_begin ("tracker-dbus-test.c",
"Test request (%s))",
"--TestNewOK--");
+ tracker_dbus_request_end (request, NULL);
- 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_end (request, NULL);
- exit (0);
- }
-
- 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*");
-
+ /* Comment and success case */
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);
- 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);
- }
+ /* Error case */
+ request = tracker_dbus_request_begin ("tracker-dbus-test.c",
+ "%s()",
+ __PRETTY_FUNCTION__);
- g_test_trap_assert_passed ();
+ error = g_error_new (1000, -1, "The indexer founded an error");
+ tracker_dbus_request_end (request, error);
+ g_error_free (error);
}
static void
-test_dbus_request_failed_coverage ()
+test_dbus_request (void)
{
- /* 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);
- }
+ /* Checking the logging output */
+ g_test_trap_subprocess ("/libtracker-common/tracker-dbus/request/subprocess", 0, 0);
g_test_trap_assert_passed ();
+ g_test_trap_assert_stdout ("*TestNewOK*");
+ g_test_trap_assert_stderr ("*TestCommentOK*");
+ g_test_trap_assert_stdout ("*Success*");
+ g_test_trap_assert_stderr ("*The indexer founded an error*");
}
-#endif
int
main (int argc, char **argv) {
@@ -332,18 +175,21 @@ 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);
+ g_test_add_func ("/libtracker-common/tracker-dbus/request/subprocess",
+ test_dbus_request_subprocess);
/* port to gdbus first
g_test_add_func ("/libtracker-common/tracker-dbus/request-client-lookup",
test_dbus_request_client_lookup);
g_test_add_func ("/libtracker-common/tracker-dbus/request-client-lookup",
test_dbus_request_client_lookup_monothread);
-*/
- g_test_add_func ("/libtracker-common/tracker-dbus/request_failed",
- test_dbus_request_failed);
-/* g_test_add_func ("/libtracker-common/tracker-dbus/request_failed_coverage",
+ g_test_add_func ("/libtracker-common/tracker-dbus/request_failed_coverage",
test_dbus_request_failed_coverage);
*/
result = g_test_run ();
diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c
index 4eef837ea..1f9559bf1 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",