1
0
Fork 0

Added jid_create_room_jid

This commit is contained in:
James Booth 2013-01-13 00:19:56 +00:00
parent 6607b99872
commit 3a22719bd7
3 changed files with 29 additions and 0 deletions

View File

@ -20,6 +20,7 @@
*
*/
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@ -98,6 +99,17 @@ jid_create(const gchar * const str)
}
}
Jid *
jid_create_room_jid(const char * const room, const char * const nick)
{
Jid *result;
char *jid = create_full_room_jid(room, nick);
result = jid_create(jid);
free(jid);
return result;
}
/*
* Given a full room JID of the form
* room@server/nick

View File

@ -36,6 +36,7 @@ struct jid_t {
typedef struct jid_t Jid;
Jid * jid_create(const gchar * const str);
Jid * jid_create_room_jid(const char * const room, const char * const nick);
gboolean jid_is_room(const char * const room_jid);
char * create_full_room_jid(const char * const room,

View File

@ -105,6 +105,20 @@ void create_jid_from_bare_returns_domainpart(void)
assert_string_equals("mydomain", result->domainpart);
}
void create_room_jid_returns_room(void)
{
Jid *result = jid_create_room_jid("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_room_jid("room@conference.domain.org", "myname");
assert_string_equals("myname", result->resourcepart);
}
void register_jid_tests(void)
{
TEST_MODULE("jid tests");
@ -125,4 +139,6 @@ void register_jid_tests(void)
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);
}