1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00
profanity/tests/unittests/test_jid.c

215 lines
6.1 KiB
C
Raw Normal View History

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
2016-07-24 09:59:28 -04:00
#include "xmpp/jid.h"
2013-01-12 18:10:56 -05:00
void create_jid_from_null_returns_null(void **state)
2013-01-12 18:10:56 -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
}
void create_jid_from_empty_string_returns_null(void **state)
2013-01-12 18:10:56 -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
}
void create_jid_from_full_returns_full(void **state)
2013-01-12 18:10:56 -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);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_returns_bare(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_returns_resourcepart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_returns_localpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_returns_domainpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_nolocal_returns_full(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("mydomain/laptop", result->fulljid);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_nolocal_returns_bare(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("mydomain", result->barejid);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_nolocal_returns_resourcepart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("laptop", result->resourcepart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_nolocal_returns_domainpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_full_nolocal_returns_null_localpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("mydomain/laptop");
2013-12-14 11:35:56 -05:00
assert_null(result->localpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_bare_returns_null_full(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain");
2013-12-14 11:35:56 -05:00
assert_null(result->fulljid);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_bare_returns_null_resource(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain");
2013-12-14 11:35:56 -05:00
assert_null(result->resourcepart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_bare_returns_bare(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain");
2013-12-14 11:35:56 -05:00
assert_string_equal("myuser@mydomain", result->barejid);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_bare_returns_localpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain");
2013-12-14 11:35:56 -05:00
assert_string_equal("myuser", result->localpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_jid_from_bare_returns_domainpart(void **state)
2013-01-12 18:10:56 -05:00
{
Jid *result = jid_create("myuser@mydomain");
2013-12-14 11:35:56 -05:00
assert_string_equal("mydomain", result->domainpart);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
void create_room_jid_returns_room(void **state)
2013-01-12 19:19:56 -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);
jid_destroy(result);
2013-01-12 19:19:56 -05:00
}
void create_room_jid_returns_nick(void **state)
2013-01-12 19:19:56 -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);
jid_destroy(result);
2013-01-12 19:19:56 -05:00
}
void create_with_slash_in_resource(void **state)
{
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);
jid_destroy(result);
}
void create_with_at_in_resource(void **state)
{
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);
jid_destroy(result);
}
void create_with_at_and_slash_in_resource(void **state)
{
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);
jid_destroy(result);
}
void create_full_with_trailing_slash(void **state)
{
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);
jid_destroy(result);
2013-01-12 18:10:56 -05:00
}
2014-11-26 16:59:36 -05:00
void returns_fulljid_when_exists(void **state)
2014-11-26 16:59:36 -05:00
{
Jid *jid = jid_create("localpart@domainpart/resourcepart");
2014-11-26 16:59:36 -05:00
char *result = jid_fulljid_or_barejid(jid);
2014-11-26 16:59:36 -05:00
assert_string_equal("localpart@domainpart/resourcepart", result);
jid_destroy(jid);
2014-11-26 16:59:36 -05:00
}
void returns_barejid_when_fulljid_not_exists(void **state)
2014-11-26 16:59:36 -05:00
{
Jid *jid = jid_create("localpart@domainpart");
2014-11-26 16:59:36 -05:00
char *result = jid_fulljid_or_barejid(jid);
2014-11-26 16:59:36 -05:00
assert_string_equal("localpart@domainpart", result);
jid_destroy(jid);
2016-07-24 09:59:28 -04:00
}