diff options
| -rw-r--r-- | .bzrignore | 4 | ||||
| -rw-r--r-- | Makefile | 7 | ||||
| -rwxr-xr-x | configure | 7 | ||||
| -rw-r--r-- | doc/user-guide/docbook.xsl | 1 | ||||
| -rw-r--r-- | doc/user-guide/help.xsl | 2 | ||||
| -rw-r--r-- | lib/Makefile | 3 | ||||
| -rw-r--r-- | protocols/Makefile | 3 | ||||
| -rw-r--r-- | protocols/jabber/Makefile | 3 | ||||
| -rw-r--r-- | protocols/msn/Makefile | 3 | ||||
| -rw-r--r-- | protocols/msn/sb.c | 15 | ||||
| -rw-r--r-- | protocols/oscar/Makefile | 3 | ||||
| -rw-r--r-- | protocols/yahoo/Makefile | 3 | ||||
| -rw-r--r-- | tests/Makefile | 13 | ||||
| -rw-r--r-- | tests/check.c | 61 | ||||
| -rw-r--r-- | tests/check_irc.c | 65 | ||||
| -rw-r--r-- | tests/check_md5.c | 56 | ||||
| -rw-r--r-- | tests/check_nick.c | 4 | ||||
| -rw-r--r-- | tests/check_util.c | 2 | ||||
| -rw-r--r-- | tests/testsuite.h | 6 | 
19 files changed, 244 insertions, 17 deletions
| @@ -12,3 +12,7 @@ encode  bitlbee.pc  .gdb_history  tests/check +*.gcda +*.gcov +*.gcno +*.o @@ -39,14 +39,19 @@ Makefile.settings:  clean: $(subdirs)  	rm -f *.o $(OUTFILE) core utils/bitlbeed encode decode +	$(MAKE) -C tests clean  distclean: clean $(subdirs)  	rm -f Makefile.settings config.h bitlbee.pc  	find . -name 'DEADJOE' -o -name '*.orig' -o -name '*.rej' -o -name '*~' -exec rm -f {} \; +	$(MAKE) -C test distclean -check: +check: all  	$(MAKE) -C tests +gcov: check +	gcov *.c +  install-doc:  	$(MAKE) -C doc install @@ -27,6 +27,7 @@ yahoo=1  debug=0  strip=1 +gcov=0  ipv6=1  events=glib @@ -66,6 +67,7 @@ Option		Description				Default  --debug=0/1	Disable/enable debugging		$debug  --strip=0/1	Disable/enable binary stripping		$strip +--gcov=0/1	Disable/enable test coverage reporting	$gcov  --ipv6=0/1	IPv6 socket support			$ipv6 @@ -365,6 +367,11 @@ else  	fi;  fi +if [ "$gcov" = "1" ]; then +	echo "CFLAGS+=-ftest-coverage -fprofile-arcs" >> Makefile.settings +	echo "EFLAGS+=-lgcov" >> Makefile.settings +fi +  echo  if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then  	nick=`bzr nick` diff --git a/doc/user-guide/docbook.xsl b/doc/user-guide/docbook.xsl index 9adff305..21d6b08e 100644 --- a/doc/user-guide/docbook.xsl +++ b/doc/user-guide/docbook.xsl @@ -82,6 +82,7 @@  	</xsl:template>  	<xsl:template name="cmd"> +		<xsl:param name="prefix"/>  		<xsl:variable name="thiscmd"><xsl:value-of select="$prefix"/><xsl:value-of select="@name"/></xsl:variable>  		<xsl:attribute name="id">  			<xsl:text>cmd_</xsl:text> diff --git a/doc/user-guide/help.xsl b/doc/user-guide/help.xsl index dec6a671..b7e3c371 100644 --- a/doc/user-guide/help.xsl +++ b/doc/user-guide/help.xsl @@ -30,6 +30,7 @@  	</xsl:template>  	<xsl:template name="subject"> +		<xsl:param name="id"/>  		<xsl:message><xsl:text>Processing: </xsl:text><xsl:value-of select="$id"/></xsl:message>  		<xsl:text>?</xsl:text><xsl:value-of select="$id"/><xsl:text>
</xsl:text> @@ -121,6 +122,7 @@  	</xsl:template>  	<xsl:template name="cmd"> +		<xsl:param name="prefix"/>  		<xsl:variable name="thiscmd"><xsl:value-of select="$prefix"/><xsl:value-of select="@name"/></xsl:variable>  		<xsl:message><xsl:text>Processing command '</xsl:text><xsl:value-of select="$thiscmd"/><xsl:text>'</xsl:text></xsl:message>  		<xsl:text>?</xsl:text><xsl:value-of select="$thiscmd"/><xsl:text>
</xsl:text> diff --git a/lib/Makefile b/lib/Makefile index 6408c5ba..33073c27 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r  # [SH] Phony targets  all: lib.o +check: all +gcov: +	gcov *.c  .PHONY: all clean distclean diff --git a/protocols/Makefile b/protocols/Makefile index cc45fb09..7f793bc4 100644 --- a/protocols/Makefile +++ b/protocols/Makefile @@ -25,6 +25,9 @@ LFLAGS += -r  # [SH] Phony targets  all: protocols.o +check: all +gcov: +	gcov *.c  .PHONY: all clean distclean $(subdirs) diff --git a/protocols/jabber/Makefile b/protocols/jabber/Makefile index 9b414dc8..27a29be4 100644 --- a/protocols/jabber/Makefile +++ b/protocols/jabber/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r  # [SH] Phony targets  all: jabber_mod.o +check: all +gcov:  +	gcov *.c  .PHONY: all clean distclean diff --git a/protocols/msn/Makefile b/protocols/msn/Makefile index 873c831c..f53b34ba 100644 --- a/protocols/msn/Makefile +++ b/protocols/msn/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r  # [SH] Phony targets  all: msn_mod.o +check: all +gcov:  +	gcov *.c  .PHONY: all clean distclean diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 63744cd0..7ec340bd 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -121,9 +121,10 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text )  {  	if( sb->ready )  	{ -		char cmd[1024], *buf; +		char *packet, *buf;  		int i, j; +		/* Build the message. Convert LF to CR-LF for normal messages. */  		if( strcmp( text, TYPING_NOTIFICATION_MESSAGE ) != 0 )  		{  			buf = g_new0( char, sizeof( MSN_MESSAGE_HEADERS ) + strlen( text ) * 2 ); @@ -141,19 +142,21 @@ int msn_sb_sendmessage( struct msn_switchboard *sb, char *text )  		else  		{  			i = strlen( MSN_TYPING_HEADERS ) + strlen( sb->gc->username ); -			buf = g_new0( char, strlen( MSN_TYPING_HEADERS ) + strlen( sb->gc->username ) ); +			buf = g_new0( char, i );  			i = g_snprintf( buf, i, MSN_TYPING_HEADERS, sb->gc->username );  		} -		g_snprintf( cmd, sizeof( cmd ), "MSG %d N %d\r\n", ++sb->trId, i ); -		if( msn_sb_write( sb, cmd, strlen( cmd ) ) && msn_sb_write( sb, buf, i ) ) +		/* Build the final packet (MSG command + the message). */ +		packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf ); +		g_free( buf ); +		if( msn_sb_write( sb, packet, strlen( packet ) ) )  		{ -			g_free( buf ); +			g_free( packet );  			return( 1 );  		}  		else  		{ -			g_free( buf ); +			g_free( packet );  			return( 0 );  		}  	} diff --git a/protocols/oscar/Makefile b/protocols/oscar/Makefile index 97a27299..ed2d7f83 100644 --- a/protocols/oscar/Makefile +++ b/protocols/oscar/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r  # [SH] Phony targets  all: oscar_mod.o +check: all +gcov: +	gcov *.c  .PHONY: all clean distclean diff --git a/protocols/yahoo/Makefile b/protocols/yahoo/Makefile index b4014f8a..34c3551a 100644 --- a/protocols/yahoo/Makefile +++ b/protocols/yahoo/Makefile @@ -16,6 +16,9 @@ LFLAGS += -r  # [SH] Phony targets  all: yahoo_mod.o +check: all +gcov:  +	gcov *.c  .PHONY: all clean distclean diff --git a/tests/Makefile b/tests/Makefile index ce8ed690..9dd3df7c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,12 +2,17 @@ include ../Makefile.settings  LFLAGS +=-lcheck -all: check -	./check +all: check  +	./check $(CHECKFLAGS) -main_objs = account.o bitlbee.o conf.o crypting.o help.o ini.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o storage_text.o url.o user.o util.o  +clean: +	rm -f check *.o -check: check.o check_util.o check_nick.o $(addprefix ../, $(main_objs)) ../protocols/protocols.o +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_irc.o + +check: $(test_objs) $(addprefix ../, $(main_objs)) ../protocols/protocols.o ../lib/lib.o  	@echo '*' Linking $@  	@$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(EFLAGS) diff --git a/tests/check.c b/tests/check.c index 5cfb7dfd..42ff067f 100644 --- a/tests/check.c +++ b/tests/check.c @@ -3,9 +3,23 @@  #include <gmodule.h>  #include <check.h>  #include "bitlbee.h" +#include "testsuite.h"  global_t global;	/* Against global namespace pollution */ +gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2) +{ +	int sock[2]; +	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, sock) < 0) { +		perror("socketpair"); +		return FALSE; +	} + +	*ch1 = g_io_channel_unix_new(sock[0]); +	*ch2 = g_io_channel_unix_new(sock[1]); +	return TRUE; +} +  double gettime()  {  	struct timeval time[1]; @@ -20,12 +34,53 @@ Suite *util_suite(void);  /* From check_nick.c */  Suite *nick_suite(void); -int main (void) +/* From check_md5.c */ +Suite *md5_suite(void); + +/* From check_irc.c */ +Suite *irc_suite(void); + +int main (int argc, char **argv)  {  	int nf; -	SRunner *sr = srunner_create(util_suite()); +	SRunner *sr; +	GOptionContext *pc; +	gboolean no_fork = FALSE; +	gboolean verbose = FALSE; +	GOptionEntry options[] = { +		{"no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" }, +		{"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, +		{ NULL } +	}; +	int i; + +	pc = g_option_context_new(""); +	g_option_context_add_main_entries(pc, options, NULL); + +	if(!g_option_context_parse(pc, &argc, &argv, NULL)) +		return 1; + +	g_option_context_free(pc); + +	log_init(); + +	if (verbose) { +		log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); +		log_link( LOGLVL_DEBUG, LOGOUTPUT_CONSOLE ); +		log_link( LOGLVL_INFO, LOGOUTPUT_CONSOLE ); +		log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE ); +	} + +	global.conf = conf_load( 0, NULL); +	global.conf->runmode = RUNMODE_DAEMON; + +	sr = srunner_create(util_suite());  	srunner_add_suite(sr, nick_suite()); -	srunner_run_all (sr, CK_NORMAL); +	srunner_add_suite(sr, md5_suite()); +	srunner_add_suite(sr, irc_suite()); +	if (no_fork) +		srunner_set_fork_status(sr, CK_NOFORK); +	srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL);  	nf = srunner_ntests_failed(sr);  	srunner_free(sr);  	return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/check_irc.c b/tests/check_irc.c new file mode 100644 index 00000000..c1cf05a5 --- /dev/null +++ b/tests/check_irc.c @@ -0,0 +1,65 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "irc.h" +#include "testsuite.h" + +START_TEST(test_connect) +	GIOChannel *ch1, *ch2; +	irc_t *irc; +	char *raw; +	fail_unless(g_io_channel_pair(&ch1, &ch2)); + +	irc = irc_new(g_io_channel_unix_get_fd(ch1)); + +	irc_free(irc); + +	fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); +	 +	fail_if(strcmp(raw, "") != 0); + +	g_free(raw); +END_TEST + +START_TEST(test_login) +	GIOChannel *ch1, *ch2; +	irc_t *irc; +	GError *error = NULL; +	char *raw; +	fail_unless(g_io_channel_pair(&ch1, &ch2)); + +	g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL); +	g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL); + +	irc = irc_new(g_io_channel_unix_get_fd(ch1)); + +	fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n" +			"USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); +	fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL); + +	g_main_iteration(FALSE); +	irc_free(irc); + +	fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); +	 +	fail_unless(strstr(raw, "001") != NULL); +	fail_unless(strstr(raw, "002") != NULL); +	fail_unless(strstr(raw, "003") != NULL); +	fail_unless(strstr(raw, "004") != NULL); +	fail_unless(strstr(raw, "005") != NULL); + +	g_free(raw); +END_TEST + +Suite *irc_suite (void) +{ +	Suite *s = suite_create("IRC"); +	TCase *tc_core = tcase_create("Core"); +	suite_add_tcase (s, tc_core); +	tcase_add_test (tc_core, test_connect); +	tcase_add_test (tc_core, test_login); +	return s; +} diff --git a/tests/check_md5.c b/tests/check_md5.c new file mode 100644 index 00000000..4b99d300 --- /dev/null +++ b/tests/check_md5.c @@ -0,0 +1,56 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "md5.h" + +/* From RFC 1321 */ +struct md5_test { +	const char *str; +	md5_byte_t expected[16]; +} tests[] = { +	{ "",  +		{ 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, +	{ "a", +		{ 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, +	{ "abc",  +		{ 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } }, +	{ "message digest",  +		{ 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } }, +	{ "abcdefghijklmnopqrstuvwxyz",  +		{ 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } }, +	{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", +	    { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } }, +	{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890",  +		{ 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }, + +	{ NULL }, +}; + +static void check_sums(int l) +{ +	int i; +	for (i = 0; tests[i].str; i++) { +		md5_byte_t sum[16]; +  		tcase_fn_start (tests[i].str, __FILE__, __LINE__); +		md5_state_t state; +		int di; + +		md5_init(&state); +		md5_append(&state, (const md5_byte_t *)tests[i].str, strlen(tests[i].str)); +		md5_finish(&state, sum); + +		fail_if(memcmp(tests[i].expected, sum, 16) != 0, "%s failed", tests[i].str); +	} +} + +Suite *md5_suite (void) +{ +	Suite *s = suite_create("MD5"); +	TCase *tc_core = tcase_create("Core"); +	suite_add_tcase (s, tc_core); +	tcase_add_test (tc_core, check_sums); +	return s; +} diff --git a/tests/check_nick.c b/tests/check_nick.c index 5858e512..714c4fdc 100644 --- a/tests/check_nick.c +++ b/tests/check_nick.c @@ -5,7 +5,7 @@  #include <string.h>  #include "irc.h"  #include "set.h" -#include "util.h" +#include "misc.h"  START_TEST(test_nick_strip)  { @@ -22,7 +22,7 @@ START_TEST(test_nick_strip)  		NULL };  	for (i = 0; get[i]; i++) { -		char copy[30]; +		char copy[60];  		strcpy(copy, get[i]);  		nick_strip(copy);  		fail_unless (strcmp(copy, expected[i]) == 0,  diff --git a/tests/check_util.c b/tests/check_util.c index e771238f..ee365735 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -5,7 +5,7 @@  #include <string.h>  #include "irc.h"  #include "set.h" -#include "util.h" +#include "misc.h"  START_TEST(test_strip_linefeed)  { diff --git a/tests/testsuite.h b/tests/testsuite.h new file mode 100644 index 00000000..dacaf8a3 --- /dev/null +++ b/tests/testsuite.h @@ -0,0 +1,6 @@ +#ifndef __BITLBEE_CHECK_H__ +#define __BITLBEE_CHECK_H__  + +gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2); + +#endif /* __BITLBEE_CHECK_H__ */ | 
