1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-27 20:30:13 -04:00

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 <string.h>
#include <glib.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 * Given a full room JID of the form
* room@server/nick * room@server/nick

View File

@ -36,6 +36,7 @@ struct jid_t {
typedef struct jid_t Jid; typedef struct jid_t Jid;
Jid * jid_create(const gchar * const str); 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); gboolean jid_is_room(const char * const room_jid);
char * create_full_room_jid(const char * const room, 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); 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) void register_jid_tests(void)
{ {
TEST_MODULE("jid tests"); 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_bare);
TEST(create_jid_from_bare_returns_localpart); TEST(create_jid_from_bare_returns_localpart);
TEST(create_jid_from_bare_returns_domainpart); TEST(create_jid_from_bare_returns_domainpart);
TEST(create_room_jid_returns_room);
TEST(create_room_jid_returns_nick);
} }