about summary refs log tree commit diff stats
path: root/tests/test_jid.c
blob: 0b9da5ab9dec94f9187b73352a2482a71515800e (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#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_from_bare_and_resource("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_from_bare_and_resource("room@conference.domain.org", "myname");

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

void create_with_slash_in_resource(void)
{
    Jid *result = jid_create("room@conference.domain.org/my/nick");

    assert_string_equals("room", result->localpart);
    assert_string_equals("conference.domain.org", result->domainpart);
    assert_string_equals("my/nick", result->resourcepart);
    assert_string_equals("room@conference.domain.org", result->barejid);
    assert_string_equals("room@conference.domain.org/my/nick", result->fulljid);
}

void create_with_at_in_resource(void)
{
    Jid *result = jid_create("room@conference.domain.org/my@nick");

    assert_string_equals("room", result->localpart);
    assert_string_equals("conference.domain.org", result->domainpart);
    assert_string_equals("my@nick", result->resourcepart);
    assert_string_equals("room@conference.domain.org", result->barejid);
    assert_string_equals("room@conference.domain.org/my@nick", result->fulljid);
}

void create_with_at_and_slash_in_resource(void)
{
    Jid *result = jid_create("room@conference.domain.org/my@nick/something");

    assert_string_equals("room", result->localpart);
    assert_string_equals("conference.domain.org", result->domainpart);
    assert_string_equals("my@nick/something", result->resourcepart);
    assert_string_equals("room@conference.domain.org", result->barejid);
    assert_string_equals("room@conference.domain.org/my@nick/something", result->fulljid);
}

void create_full_with_trailing_slash(void)
{
    Jid *result = jid_create("room@conference.domain.org/nick/");

    assert_string_equals("room", result->localpart);
    assert_string_equals("conference.domain.org", result->domainpart);
    assert_string_equals("nick/", result->resourcepart);
    assert_string_equals("room@conference.domain.org", result->barejid);
    assert_string_equals("room@conference.domain.org/nick/", result->fulljid);
}

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);
    TEST(create_with_slash_in_resource);
    TEST(create_with_at_in_resource);
    TEST(create_with_at_and_slash_in_resource);
    TEST(create_full_with_trailing_slash);
}