diff options
| -rw-r--r-- | .bzrignore | 4 | ||||
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | bitlbee.c | 2 | ||||
| -rw-r--r-- | conf.c | 2 | ||||
| -rwxr-xr-x | configure | 18 | ||||
| -rw-r--r-- | doc/user-guide/docbook.xsl | 1 | ||||
| -rw-r--r-- | doc/user-guide/help.xsl | 2 | ||||
| -rw-r--r-- | ipc.c | 6 | ||||
| -rw-r--r-- | irc.c | 14 | ||||
| -rw-r--r-- | irc_commands.c | 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-- | storage_xml.c | 2 | ||||
| -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 | 
25 files changed, 272 insertions, 28 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 @@ -68,6 +68,7 @@ int bitlbee_daemon_init()  	setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) );  #ifdef IPV6 +	memset( &listen_addr6, 0, sizeof( listen_addr6 ) );  	listen_addr6.sin6_family = AF_INET6;  	listen_addr6.sin6_port = htons( global.conf->port );  	if( ( i = inet_pton( AF_INET6, ipv6_wrap( global.conf->iface ), &listen_addr6.sin6_addr ) ) != 1 ) @@ -75,6 +76,7 @@ int bitlbee_daemon_init()  		/* Forget about IPv6 in this function. */  		use_ipv6 = 0;  #endif +		memset( &listen_addr, 0, sizeof( listen_addr ) );  		listen_addr.sin_family = AF_INET;  		listen_addr.sin_port = htons( global.conf->port );  		if( strcmp( global.conf->iface, "::" ) == 0 ) @@ -62,7 +62,7 @@ conf_t *conf_load( int argc, char *argv[] )  	conf->oper_pass = NULL;  	conf->configdir = g_strdup( CONFIG );  	conf->plugindir = g_strdup( PLUGINDIR ); -	conf->pidfile = g_strdup( "/var/run/bitlbee.pid" ); +	conf->pidfile = g_strdup( PIDFILE );  	conf->motdfile = g_strdup( ETCDIR "/motd.txt" );  	conf->ping_interval = 180;  	conf->ping_timeout = 300; @@ -17,7 +17,7 @@ plugindir='$prefix/lib/bitlbee/'  includedir='$prefix/include/bitlbee/'  libevent='/usr/'  pidfile='/var/run/bitlbee.pid' -ipcsocket='/var/run/bitlbee' +ipcsocket='/var/run/bitlbee.sock'  pcdir='$prefix/lib/pkgconfig'  msn=1 @@ -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 @@ -104,7 +106,6 @@ MANDIR=$mandir  DATADIR=$datadir  PLUGINDIR=$plugindir  CONFIG=$config -IPCSOCKET=$ipcsocket  INCLUDEDIR=$includedir  PCDIR=$pcdir @@ -344,6 +345,11 @@ fi  if [ "$ldap" = 0 ]; then  	echo "#undef WITH_LDAP" >> config.h  elif [ "$ldap" = 1 ]; then +	echo +	echo 'LDAP support is a work in progress and does NOT work AT ALL right now.' +	echo +	exit 1 +	  	echo "#define WITH_LDAP 1" >> config.h  	STORAGES="$STORAGES ldap"  fi @@ -373,6 +379,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` @@ -465,6 +476,9 @@ SunOS )  	echo 'EFLAGS+=-lresolv -lnsl -lsocket' >> Makefile.settings  	echo 'STRIP=\# skip strip' >> Makefile.settings  ;; +AIX ) +	echo 'EFLAGS+=-Wl,-brtl' >> Makefile.settings +;;  CYGWIN* )  	echo 'Cygwin is not officially supported.'  ;; 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> @@ -98,7 +98,7 @@ static const command_t ipc_master_commands[] = {  	{ "hello",      0, ipc_master_cmd_client,     0 },  	{ "die",        0, ipc_master_cmd_die,        0 },  	{ "wallops",    1, NULL,                      IPC_CMD_TO_CHILDREN }, -	{ "lilo",       1, NULL,                      IPC_CMD_TO_CHILDREN }, +	{ "wall",       1, NULL,                      IPC_CMD_TO_CHILDREN },  	{ "opermsg",    1, NULL,                      IPC_CMD_TO_CHILDREN },  	{ "rehash",     0, ipc_master_cmd_rehash,     0 },  	{ "kill",       2, NULL,                      IPC_CMD_TO_CHILDREN }, @@ -121,7 +121,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )  		irc_write( irc, ":%s WALLOPS :%s", irc->myhost, cmd[1] );  } -static void ipc_child_cmd_lilo( irc_t *irc, char **cmd ) +static void ipc_child_cmd_wall( irc_t *irc, char **cmd )  {  	if( !( irc->status & USTATUS_LOGGED_IN ) )  		return; @@ -174,7 +174,7 @@ static void ipc_child_cmd_hello( irc_t *irc, char **cmd )  static const command_t ipc_child_commands[] = {  	{ "die",        0, ipc_child_cmd_die,         0 },  	{ "wallops",    1, ipc_child_cmd_wallops,     0 }, -	{ "lilo",       1, ipc_child_cmd_lilo,        0 }, +	{ "wall",       1, ipc_child_cmd_wall,        0 },  	{ "opermsg",    1, ipc_child_cmd_opermsg,     0 },  	{ "rehash",     0, ipc_child_cmd_rehash,      0 },  	{ "kill",       2, ipc_child_cmd_kill,        0 }, @@ -255,7 +255,12 @@ void irc_free(irc_t * irc)  		query_del(irc, irc->queries);  	while (irc->accounts) -		account_del(irc, irc->accounts); +		if (irc->accounts->gc == NULL) +			account_del(irc, irc->accounts); +		else +			/* Nasty hack, but account_del() doesn't work in this +			   case and we don't want infinite loops, do we? ;-) */ +			irc->accounts = irc->accounts->next;  	while (irc->set)  		set_del(&irc->set, irc->set->key); @@ -584,8 +589,11 @@ void irc_vawrite( irc_t *irc, char *format, va_list params )  		   immediately. If it returns TRUE, it should be called again, so add the event to  		   the queue. If it's FALSE, we emptied the buffer and saved ourselves some work  		   in the event queue. */ -		if( bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ) ) -			irc->w_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc ); +		/* Really can't be done as long as the code doesn't do error checking very well: +		if( bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ) ) */ +		 +		/* So just always do it via the event handler. */ +		irc->w_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc );  	}  	return; diff --git a/irc_commands.c b/irc_commands.c index 47d9e8cb..b1045c93 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -592,7 +592,7 @@ static const command_t irc_commands[] = {  	{ "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },  	{ "die",         0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "wallops",     1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, -	{ "lilo",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, +	{ "wall",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY },  	{ "restart",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },  	{ "kill",        2, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, 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 c084b1f4..3c9e4949 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/storage_xml.c b/storage_xml.c index ba311120..00fca425 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -394,7 +394,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )  		return STORAGE_ALREADY_EXISTS;  	strcat( path, "~" ); -	if( ( fd = open( path, O_WRONLY | O_CREAT, 0600 ) ) < 0 ) +	if( ( fd = open( path, O_WRONLY | O_CREAT | O_TRUNC, 0600 ) ) < 0 )  	{  		irc_usermsg( irc, "Error while opening configuration file." );  		return STORAGE_OTHER_ERROR; 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__ */ | 
