summaryrefslogtreecommitdiff
path: root/tests/test-jid-decode.c
blob: b1c835fe14e4237a1216511166195c624be384e9 (plain)
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

#include "config.h"

#include <string.h>

#include <wocky/wocky.h>

#include "src/util.h"

static void
test_pass (
    const gchar *jid,
    const gchar *expected_node,
    const gchar *expected_domain,
    const gchar *expected_resource)
{
  gchar *node = NULL;
  gchar *domain = NULL;
  gchar *resource = NULL;

  g_assert (wocky_decode_jid (jid, &node, &domain, &resource));
  g_assert (!tp_strdiff (expected_node, node));
  g_assert (!tp_strdiff (expected_domain, domain));
  g_assert (!tp_strdiff (expected_resource, resource));
  g_free (node);
  g_free (domain);
  g_free (resource);
}

static void
test_fail (const gchar *jid)
{
  gchar *node = NULL;
  gchar *domain = NULL;
  gchar *resource = NULL;

  g_assert (!wocky_decode_jid (jid, &node, &domain, &resource));
  g_assert (node == NULL);
  g_assert (domain == NULL);
  g_assert (resource == NULL);
}

int
main (void)
{
  test_fail ("");
  test_pass ("bar", NULL, "bar", NULL);
  test_pass ("foo@bar", "foo", "bar", NULL);
  test_pass ("foo@bar/baz", "foo", "bar", "baz");
  test_fail ("@bar");
  test_fail ("foo@bar/");
  test_pass ("Foo@Bar/Baz", "foo", "bar", "Baz");
  test_fail ("foo@@");
  test_fail ("foo&bar@baz");
  test_pass ("foo/bar@baz", NULL, "foo", "bar@baz");
  test_pass ("foo@bar/foo@bar/foo@bar", "foo", "bar", "foo@bar/foo@bar");

  return 0;
}