diff options
| -rw-r--r-- | protocols/jabber/jabber_util.c | 4 | ||||
| -rw-r--r-- | tests/Makefile | 2 | ||||
| -rw-r--r-- | tests/check.c | 4 | ||||
| -rw-r--r-- | tests/check_jabber_sasl.c | 1 | ||||
| -rw-r--r-- | tests/check_jabber_util.c | 77 | 
5 files changed, 85 insertions, 3 deletions
| diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 518624f6..78d1009c 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -524,7 +524,9 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		/* If there's only one item in the list (and if the resource  		   matches), removing it is simple. (And the hash reference  		   should be removed too!) */ -		if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) +		if( bud->next == NULL && +		    ( ( s == NULL && bud->resource == NULL ) || +		      ( bud->resource && s && g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) )  		{  			g_hash_table_remove( jd->buddies, bud->bare_jid );  			g_free( bud->bare_jid ); diff --git a/tests/Makefile b/tests/Makefile index ae76fef5..db145503 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -12,7 +12,7 @@ distclean: clean  main_objs = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_xml.o storage_text.o user.o -test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o +test_objs = check.o check_util.o check_nick.o check_md5.o check_arc.o check_irc.o check_help.o check_user.o check_crypting.o check_set.o check_jabber_sasl.o check_jabber_util.o  check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o  	@echo '*' Linking $@ diff --git a/tests/check.c b/tests/check.c index b3ffb957..874acdd2 100644 --- a/tests/check.c +++ b/tests/check.c @@ -68,6 +68,9 @@ Suite *set_suite(void);  /* From check_jabber_sasl.c */  Suite *jabber_sasl_suite(void); +/* From check_jabber_sasl.c */ +Suite *jabber_util_suite(void); +  int main (int argc, char **argv)  {  	int nf; @@ -114,6 +117,7 @@ int main (int argc, char **argv)  	srunner_add_suite(sr, crypting_suite());  	srunner_add_suite(sr, set_suite());  	srunner_add_suite(sr, jabber_sasl_suite()); +	srunner_add_suite(sr, jabber_util_suite());  	if (no_fork)  		srunner_set_fork_status(sr, CK_NOFORK);  	srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); diff --git a/tests/check_jabber_sasl.c b/tests/check_jabber_sasl.c index 6bceeb88..63118d39 100644 --- a/tests/check_jabber_sasl.c +++ b/tests/check_jabber_sasl.c @@ -4,7 +4,6 @@  #include <check.h>  #include <string.h>  #include <stdio.h> -#include "arc.h"  char *sasl_get_part( char *data, char *field ); diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c new file mode 100644 index 00000000..2d54ed23 --- /dev/null +++ b/tests/check_jabber_util.c @@ -0,0 +1,77 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "jabber/jabber.h" + +static struct im_connection *ic; + +static void check_buddy_add(int l) +{ +	struct jabber_buddy *budw1, *budw2, *budw3, *budw4, *budn; +	int i; +	 +	budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" ); +	budw1->last_act = time( NULL ) - 100; +	budw2 = jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ); +	budw2->priority = 2; +	budw2->last_act = time( NULL ); +	budw3 = jabber_buddy_add( ic, "wilmer@gaast.net/Druif" ); +	budw3->last_act = time( NULL ) - 200; +	budw3->priority = 4; +	/* TODO(wilmer): Shouldn't this just return budw3? */ +	fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/druif" ) != NULL ); +	 +	budn = jabber_buddy_add( ic, "nekkid@lamejab.net" ); +	/* Shouldn't be allowed if there's already a bare JID. */ +	fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) ); +	 +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", GET_BUDDY_EXACT ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", GET_BUDDY_CREAT ) == budw1 ); + +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw3 ); +	 +	set_setstr( &ic->acc->set, "resource_select", "activity" ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw2 ); +	 +	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) ); +	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", GET_BUDDY_CREAT ) ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_EXACT ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_CREAT ) == budn ); +	 +	jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); +	 +	fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); +	 +	fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); + +	fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) ); +	fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) ); +	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) ); +} + +Suite *jabber_util_suite (void) +{ +	Suite *s = suite_create("jabber/util"); +	TCase *tc_core = tcase_create("Buddy"); +	struct jabber_data *jd; +	 +	ic = g_new0( struct im_connection, 1 ); +	ic->acc = g_new0( account_t, 1 ); +	ic->proto_data = jd = g_new0( struct jabber_data, 1 ); +	jd->buddies = g_hash_table_new( g_str_hash, g_str_equal ); +	set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc ); +	 +	suite_add_tcase (s, tc_core); +	tcase_add_test (tc_core, check_buddy_add); +	return s; +} | 
