summaryrefslogtreecommitdiff
path: root/tests/libtracker-common
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-10-14 13:25:36 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-10-14 15:31:08 +0200
commite559b39ee6cbfeee4ca1bf1e056d915b923fca12 (patch)
tree74bb3b54ea3b725dec558a2f40168eada93deb9f /tests/libtracker-common
parentfc27b4e3f3acc2f6b0db3d37a84210d2750c5806 (diff)
downloadtracker-e559b39ee6cbfeee4ca1bf1e056d915b923fca12.tar.gz
tests,libtracker-common: fix tests expecting stdout/stderr messages
We need to make sure that tests expecting messages from stdout/stderr are not dependent on the specific value set for G_MESSAGES_DEBUG. In other words, make sure that the trap fork tests dump to stdout/stderr unconditionally. Before this fix, we had: $ ./tracker-dbus /libtracker-common/tracker-dbus/slist_to_strv_ok: OK /libtracker-common/tracker-dbus/request: ** Tracker:ERROR:tracker-dbus-test.c:131:test_dbus_request: stdout of child process (12948) failed to match: *TestNewOK* Aborted (core dumped) $ G_MESSAGES_DEBUG=all ./tracker-dbus /libtracker-common/tracker-dbus/slist_to_strv_ok: OK /libtracker-common/tracker-dbus/request: Tracker-DEBUG: <--- [1|0] Test request (--TestNewOK--)) OK /libtracker-common/tracker-dbus/request_failed: Tracker-DEBUG: <--- [2|0] test_dbus_request_failed() OK Now, we just have: $ ./tracker-dbus /libtracker-common/tracker-dbus/slist_to_strv_ok: OK /libtracker-common/tracker-dbus/request: OK /libtracker-common/tracker-dbus/request_failed: OK https://bugzilla.gnome.org/show_bug.cgi?id=710092
Diffstat (limited to 'tests/libtracker-common')
-rw-r--r--tests/libtracker-common/tracker-dbus-test.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/libtracker-common/tracker-dbus-test.c b/tests/libtracker-common/tracker-dbus-test.c
index fc6bd38c1..8a6299ab2 100644
--- a/tests/libtracker-common/tracker-dbus-test.c
+++ b/tests/libtracker-common/tracker-dbus-test.c
@@ -26,6 +26,23 @@
#include <tracker-test-helpers.h>
+/* Log handler to use in the trap fork tests; where we make sure to dump to
+ * stdout/stderr, regardless of G_MESSAGES_DEBUG being set or not */
+static void
+log_handler (const gchar *domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ if (log_level & G_LOG_LEVEL_ERROR ||
+ log_level & G_LOG_LEVEL_CRITICAL ||
+ log_level & G_LOG_LEVEL_WARNING ||
+ log_level & G_LOG_LEVEL_MESSAGE)
+ g_printerr ("%s\n", message);
+ else
+ g_print ("%s\n", message);
+}
+
static void
slist_to_strv (gboolean utf8)
{
@@ -50,6 +67,7 @@ slist_to_strv (gboolean utf8)
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);
}
@@ -105,6 +123,7 @@ test_dbus_request_failed (void)
/* 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);
}
@@ -121,6 +140,7 @@ test_dbus_request ()
/* 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--");
@@ -135,6 +155,7 @@ test_dbus_request ()
"--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--");
@@ -145,6 +166,7 @@ test_dbus_request ()
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);
}
@@ -163,6 +185,7 @@ test_dbus_request_client_lookup ()
/* 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--");
@@ -178,6 +201,7 @@ test_dbus_request_client_lookup ()
"--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--");
@@ -188,6 +212,7 @@ test_dbus_request_client_lookup ()
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--");
@@ -198,6 +223,7 @@ test_dbus_request_client_lookup ()
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--");
@@ -208,6 +234,7 @@ test_dbus_request_client_lookup ()
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);
}
@@ -226,6 +253,8 @@ test_dbus_request_client_lookup_monothread ()
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))",
@@ -259,6 +288,8 @@ test_dbus_request_failed_coverage ()
GError *error = NULL;
TrackerDBusRequest *request;
+ g_log_set_default_handler (log_handler, NULL);
+
tracker_dbus_enable_client_lookup (TRUE);
/* Using GError */
@@ -299,7 +330,7 @@ main (int argc, char **argv) {
test_async_queue_to_strv_nonutf8);
*/
- g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_ok",
+ g_test_add_func ("/libtracker-common/tracker-dbus/slist_to_strv_ok",
test_slist_to_strv);
g_test_add_func ("/libtracker-common/tracker-dbus/request",
test_dbus_request);