about summary refs log tree commit diff stats
path: root/tests/test_jid.c
blob: 99ae4f12605fb67e385ff1c096c6fbbb9b21fce6 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdlib.h>
#include <string.h>
#include <head-unit.h>
#include "jid.h"

void create_jid_from_null_returns_null(void)
{
    Jid *result = jid_create(NULL);
    assert_is_null(result);
}

void create_jid_from_empty_string_returns_null(void)
{
    Jid *result = jid_create("");
    assert_is_null(result);
}

void create_jid_from_full_returns_full(void)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equals("myuser@mydomain/laptop", result->fulljid);
}

void create_jid_from_full_returns_bare(void)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equals("myuser@mydomain", result->barejid);
}

void create_jid_from_full_returns_resourcepart(void)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equals("laptop", result->resourcepart);
}

void create_jid_from_full_returns_localpart(void)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equals("myuser", result->localpart);
}

void create_jid_from_full_returns_domainpart(void)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equals("mydomain", result->domainpart);
}

void create_jid_from_full_nolocal_returns_full(void)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equals("mydomain/laptop", result->fulljid);
}

void create_jid_from_full_nolocal_returns_bare(void)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equals("mydomain", result->barejid);
}

void create_jid_from_full_nolocal_returns_resourcepart(void)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equals("laptop", result->resourcepart);
}

void create_jid_from_full_nolocal_returns_domainpart(void)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equals("mydomain", result->domainpart);
}

void create_jid_from_full_nolocal_returns_null_localpart(void)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_is_null(result->localpart);
}

void create_jid_from_bare_returns_null_full(void)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_is_null(result->fulljid);
}

void create_jid_from_bare_returns_null_resource(void)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_is_null(result->resourcepart);
}

void create_jid_from_bare_returns_bare(void)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equals("myuser@mydomain", result->barejid);
}

void create_jid_from_bare_returns_localpart(void)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equals("myuser", result->localpart);
}

void create_jid_from_bare_returns_domainpart(void)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equals("mydomain", result->domainpart);
}

void create_room_jid_returns_room(void)
{
    Jid *result = jid_create_room_jid("room@conference.domain.org", "myname");

    assert_string_equals("room@conference.domain.org", result->barejid);
}

void create_room_jid_returns_nick(void)
{
    Jid *result = jid_create_room_jid("room@conference.domain.org", "myname");

    assert_string_equals("myname", result->resourcepart);
}

void register_jid_tests(void)
{
    TEST_MODULE("jid tests");
    TEST(create_jid_from_null_returns_null);
    TEST(create_jid_from_empty_string_returns_null);
    TEST(create_jid_from_full_returns_full);
    TEST(create_jid_from_full_returns_bare);
    TEST(create_jid_from_full_returns_resourcepart);
    TEST(create_jid_from_full_returns_localpart);
    TEST(create_jid_from_full_returns_domainpart);
    TEST(create_jid_from_full_nolocal_returns_full);
    TEST(create_jid_from_full_nolocal_returns_bare);
    TEST(create_jid_from_full_nolocal_returns_resourcepart);
    TEST(create_jid_from_full_nolocal_returns_domainpart);
    TEST(create_jid_from_full_nolocal_returns_null_localpart);
    TEST(create_jid_from_bare_returns_null_full);
    TEST(create_jid_from_bare_returns_null_resource);
    TEST(create_jid_from_bare_returns_bare);
    TEST(create_jid_from_bare_returns_localpart);
    TEST(create_jid_from_bare_returns_domainpart);
    TEST(create_room_jid_returns_room);
    TEST(create_room_jid_returns_nick);
}