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