File: debug-domain.c

package info (click to toggle)
telepathy-glib 0.24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 34,628 kB
  • sloc: ansic: 124,643; xml: 34,410; sh: 11,299; python: 3,520; makefile: 1,727; cpp: 16
file content (71 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "config.h"

#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_log 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 (log_level, ==, G_LOG_LEVEL_DEBUG);
  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;

  tp_debug_set_flags ("all");

  g_log_set_default_handler (handler, NULL);

  for (; items[item].domain != NULL; item++)
    {
      i = items[item];
      _tp_log (G_LOG_LEVEL_DEBUG, i.flag, "foo");
    }

#else
  g_print ("Not running test-debug-domain test as ENABLE_DEBUG is undefined\n");
#endif
  return 0;
}