[telepathy-glib/master] tests: add a test for debug domains being set correctly

Jonny Lamb jonny.lamb at collabora.co.uk
Fri Sep 4 07:05:35 PDT 2009


Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 tests/Makefile.am    |   13 +++++++--
 tests/debug-domain.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 3 deletions(-)
 create mode 100644 tests/debug-domain.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 900c281..cb672df 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,8 @@ noinst_PROGRAMS = \
     test-heap \
     test-internal-debug \
     test-intset \
-    test-util
+    test-util \
+    test-debug-domain
 
 TESTS = $(noinst_PROGRAMS) \
     all-errors-documented.py
@@ -54,10 +55,16 @@ test_intset_SOURCES = \
 test_availability_cmp_SOURCES = \
     availability-cmp.c
 
-# this needs to link against the static convenience library so that
-# _tp_debug is still visible
+test_debug_domain_SOURCES = \
+    debug-domain.c
+
 test_internal_debug_SOURCES = \
     internal-debug.c
+
+# this needs to link against the static convenience library so that
+# _tp_debug is still visible
+test_debug_domain_LDADD = \
+    $(top_builddir)/telepathy-glib/libtelepathy-glib-internal.la
 test_internal_debug_LDADD = \
     $(top_builddir)/telepathy-glib/libtelepathy-glib-internal.la
 
diff --git a/tests/debug-domain.c b/tests/debug-domain.c
new file mode 100644
index 0000000..7614c84
--- /dev/null
+++ b/tests/debug-domain.c
@@ -0,0 +1,70 @@
+#include <glib.h>
+
+#include <telepathy-glib/util.h>
+
+#include "telepathy-glib/debug-internal.h"
+
+/* Only run test if ENABLE_DEBUG is defined, otherwise we won't have
+ * _tp_debug and the TpDebugFlags enum. */
+#ifdef ENABLE_DEBUG
+
+typedef struct
+{
+  guint flag;
+  const gchar *domain;
+} TestItem;
+
+static TestItem items[] = {
+  { TP_DEBUG_GROUPS, "groups" },
+  { TP_DEBUG_GROUPS | TP_DEBUG_PROPERTIES, "groups" },
+  { TP_DEBUG_GROUPS | TP_DEBUG_DISPATCHER, "groups" },
+  { TP_DEBUG_PROXY | TP_DEBUG_CHANNEL, "channel" },
+  { 1 << 31, "misc" },
+  { TP_DEBUG_ACCOUNTS, "accounts" },
+  { TP_DEBUG_PROXY | TP_DEBUG_HANDLES | TP_DEBUG_PRESENCE, "presence" },
+  { 0, NULL },
+};
+static guint item = 0;
+
+static void
+handler (const gchar *log_domain,
+    GLogLevelFlags log_level,
+    const gchar *message,
+    gpointer user_data)
+{
+  TestItem i = items[item];
+  gchar **parts;
+
+  parts = g_strsplit (log_domain, "/", -1);
+
+  g_assert_cmpuint (g_strv_length (parts), ==, 2);
+  g_assert (!tp_strdiff (parts[0], "tp-glib"));
+  g_assert (!tp_strdiff (parts[1], i.domain));
+  g_assert (!tp_strdiff (message, "foo"));
+
+  g_strfreev (parts);
+}
+#endif
+
+int main (int argc, char **argv)
+{
+#ifdef ENABLE_DEBUG
+  TestItem i;
+
+  g_type_init ();
+
+  tp_debug_set_flags ("all");
+
+  g_log_set_default_handler (handler, NULL);
+
+  for (; items[item].domain != NULL; item++)
+    {
+      i = items[item];
+      _tp_debug (i.flag, "foo");
+    }
+
+#else
+  g_print ("Not running test-debug-domain test as ENABLE_DEBUG is undefined\n");
+#endif
+  return 0;
+}
-- 
1.5.6.5



More information about the telepathy-commits mailing list