[libgdata] Added functions gdata_test_debug_output, gdata_test_debug_handler and GSList message_list for collec
- From: Peteris Krisjanis <peterisk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] Added functions gdata_test_debug_output, gdata_test_debug_handler and GSList message_list for collec
- Date: Fri, 21 Jun 2013 15:58:54 +0000 (UTC)
commit b116aade27c2a4b4229ba0b6cca4a425f9dfcb38
Author: Peteris Krisjanis <pecisk gmail com>
Date: Fri Jun 21 18:55:51 2013 +0300
Added functions gdata_test_debug_output, gdata_test_debug_handler and GSList message_list for collecting
debug messages in memory and printing out only when needed (including pretty printing XML). Closes
https://bugzilla.gnome.org/show_bug.cgi?id=627895
gdata/tests/common.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
gdata/tests/common.h | 3 ++
2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/gdata/tests/common.c b/gdata/tests/common.c
index 80f937d..6f6c81a 100644
--- a/gdata/tests/common.c
+++ b/gdata/tests/common.c
@@ -32,6 +32,15 @@ static gboolean no_internet = FALSE;
/* %TRUE if interactive tests should be skipped because we're running automatically (for example) */
static gboolean no_interactive = FALSE;
+/* declaration of debug handler */
+static void gdata_test_debug_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar
*message, gpointer user_data);
+
+/* declaration of printerr handler */
+static void gdata_test_assert_handler (const gchar *message);
+
+/* global list of debugging messages */
+static GSList *message_list = NULL;
+
void
gdata_test_init (int argc, char **argv)
{
@@ -74,6 +83,12 @@ gdata_test_init (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
+ /* Set handler of debug information */
+ g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, (GLogFunc) gdata_test_debug_handler,
message_list);
+
+ /* Set handler for printerr */
+ g_set_printerr_handler ((GPrintFunc) gdata_test_assert_handler);
+
/* Enable full debugging */
g_setenv ("LIBGDATA_DEBUG", "3" /* GDATA_LOG_FULL */, FALSE);
g_setenv ("G_MESSAGES_DEBUG", "libgdata", FALSE);
@@ -651,3 +666,55 @@ gdata_tear_down_async_test_data (GDataAsyncTestData *async_data, gconstpointer t
g_object_unref (async_data->cancellable);
g_main_loop_unref (async_data->main_loop);
}
+
+void
+gdata_test_debug_output (void)
+{
+ if (message_list == NULL) {
+ /* No debugging messages */
+ return;
+ }
+ do {
+ gchar *message = (gchar*) message_list->data;
+ if (message != NULL) {
+ if (strlen (message) > 2 && message[2] == '<') {
+ /* As debug string starts with direction indicator and space, t.i. "< ", */
+ /* we need access string starting from third character and see if it's */
+ /* looks like xml - t.i. it starts with '<' */
+ xmlChar *xml_buff;
+ int buffer_size;
+ xmlDocPtr xml_doc;
+ /* we need to cut to the begining of XML string */
+ message = message + 2;
+ /* create xml document and dump it to string buffer */
+ xml_doc = xmlParseDoc ((const xmlChar*) message);
+ xmlDocDumpFormatMemory (xml_doc, &xml_buff, &buffer_size, 1);
+ /* print out structured xml - if it's not xml, it will get error in output */
+ printf("%s", (gchar*) xml_buff);
+ /* free xml structs */
+ xmlFree (xml_buff);
+ xmlFreeDoc (xml_doc);
+ } else {
+ printf ("%s\n", (gchar*) message);
+ }
+ /* free gchar */
+ g_free ((gpointer) message_list->data);
+ }
+ /* free GSList node */
+ message_list = g_slist_delete_link (message_list, message_list);
+ } while (message_list != NULL);
+}
+
+static void
+gdata_test_debug_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer
user_data)
+{
+ /* storing debugging messages in GSList for displaying them in case of error */
+ message_list = g_slist_append (message_list, g_strdup (message));
+}
+
+static void
+gdata_test_assert_handler (const gchar *message)
+{
+ gdata_test_debug_output ();
+ printf ("%s", (gchar*) message);
+}
diff --git a/gdata/tests/common.h b/gdata/tests/common.h
index ca8f439..d754d5f 100644
--- a/gdata/tests/common.h
+++ b/gdata/tests/common.h
@@ -284,6 +284,9 @@ gboolean gdata_async_test_cancellation_cb (GDataAsyncTestData *async_data);
void gdata_set_up_async_test_data (GDataAsyncTestData *async_data, gconstpointer test_data);
void gdata_tear_down_async_test_data (GDataAsyncTestData *async_data, gconstpointer test_data);
+/* Debugging output in case of assert failure */
+void gdata_test_debug_output (void);
+
G_END_DECLS
#endif /* !GDATA_TEST_COMMON_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]