2013-12-14 11:35:56 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2013-01-12 18:10:56 -05:00
|
|
|
#include <stdlib.h>
|
2013-12-14 11:35:56 -05:00
|
|
|
|
2013-01-12 18:10:56 -05:00
|
|
|
#include "jid.h"
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_null_returns_null(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create(NULL);
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_null(result);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_empty_string_returns_null(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_null(result);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_returns_full(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_returns_bare(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myuser@mydomain", result->barejid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_returns_resourcepart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("laptop", result->resourcepart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_returns_localpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myuser", result->localpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_returns_domainpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("mydomain", result->domainpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_nolocal_returns_full(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("mydomain/laptop", result->fulljid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_nolocal_returns_bare(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("mydomain", result->barejid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_nolocal_returns_resourcepart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("laptop", result->resourcepart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_nolocal_returns_domainpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("mydomain", result->domainpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_full_nolocal_returns_null_localpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("mydomain/laptop");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_null(result->localpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_bare_returns_null_full(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_null(result->fulljid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_bare_returns_null_resource(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_null(result->resourcepart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_bare_returns_bare(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myuser@mydomain", result->barejid);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_bare_returns_localpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myuser", result->localpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_jid_from_bare_returns_domainpart(void **state)
|
2013-01-12 18:10:56 -05:00
|
|
|
{
|
2013-01-12 19:05:25 -05:00
|
|
|
Jid *result = jid_create("myuser@mydomain");
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("mydomain", result->domainpart);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_room_jid_returns_room(void **state)
|
2013-01-12 19:19:56 -05:00
|
|
|
{
|
2013-01-26 20:14:59 -05:00
|
|
|
Jid *result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
2013-01-12 19:19:56 -05:00
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("room@conference.domain.org", result->barejid);
|
2013-01-12 19:19:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_room_jid_returns_nick(void **state)
|
2013-01-12 19:19:56 -05:00
|
|
|
{
|
2013-01-26 20:14:59 -05:00
|
|
|
Jid *result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
2013-01-12 19:19:56 -05:00
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
assert_string_equal("myname", result->resourcepart);
|
2013-01-12 19:19:56 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_with_slash_in_resource(void **state)
|
2013-01-26 11:13:11 -05:00
|
|
|
{
|
|
|
|
Jid *result = jid_create("room@conference.domain.org/my/nick");
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
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);
|
2013-01-26 11:13:11 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_with_at_in_resource(void **state)
|
2013-01-26 11:13:11 -05:00
|
|
|
{
|
|
|
|
Jid *result = jid_create("room@conference.domain.org/my@nick");
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
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);
|
2013-01-26 11:13:11 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_with_at_and_slash_in_resource(void **state)
|
2013-01-26 11:13:11 -05:00
|
|
|
{
|
|
|
|
Jid *result = jid_create("room@conference.domain.org/my@nick/something");
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
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);
|
2013-01-26 11:13:11 -05:00
|
|
|
}
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
void create_full_with_trailing_slash(void **state)
|
2013-01-26 11:13:11 -05:00
|
|
|
{
|
|
|
|
Jid *result = jid_create("room@conference.domain.org/nick/");
|
|
|
|
|
2013-12-14 11:35:56 -05:00
|
|
|
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);
|
2013-01-12 18:10:56 -05:00
|
|
|
}
|