about summary refs log tree commit diff stats
path: root/tests/unittests/test_jid.c
blob: b7f6ea227f8aa8b6e019949f261bbc345f6c3cfa (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
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>

#include "xmpp/jid.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void returns_fulljid_when_exists(void **state)
{
    Jid *jid = jid_create("localpart@domainpart/resourcepart");

    char *result = jid_fulljid_or_barejid(jid);

    assert_string_equal("localpart@domainpart/resourcepart", result);
}

void returns_barejid_when_fulljid_not_exists(void **state)
{
    Jid *jid = jid_create("localpart@domainpart");

    char *result = jid_fulljid_or_barejid(jid);

    assert_string_equal("localpart@domainpart", result);
}