From b4e4b958ac5db7f59f8a21c914b02d8d487de2a4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 13 Jun 2006 00:24:04 +0200 Subject: Remove unused variable. --- irc_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc_commands.c b/irc_commands.c index dc59f7ee..75ab4dbd 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -320,7 +320,7 @@ static void irc_cmd_userhost( irc_t *irc, char **cmd ) static void irc_cmd_ison( irc_t *irc, char **cmd ) { user_t *u; - char buff[IRC_MAX_LINE], *s; + char buff[IRC_MAX_LINE]; int lenleft, i; buff[0] = '\0'; -- cgit v1.2.3 From c2fa8279933a103d6576d891e85c1801d90c65ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Jun 2006 13:48:52 +0200 Subject: Add unit testing infrastructure. --- .bzrignore | 1 + Makefile | 3 +++ tests/Makefile | 14 ++++++++++++++ tests/check.c | 17 +++++++++++++++++ tests/check_util.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 tests/Makefile create mode 100644 tests/check.c create mode 100644 tests/check_util.c diff --git a/.bzrignore b/.bzrignore index 802cb1a0..cddd9fb1 100644 --- a/.bzrignore +++ b/.bzrignore @@ -11,3 +11,4 @@ decode encode bitlbee.pc .gdb_history +tests/check diff --git a/Makefile b/Makefile index 51ffc83f..6f1d2d4a 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,9 @@ distclean: clean $(subdirs) rm -f Makefile.settings config.h find . -name 'DEADJOE' -o -name '*.orig' -o -name '*.rej' -o -name '*~' -exec rm -f {} \; +check: + $(MAKE) -C tests + install-doc: $(MAKE) -C doc install diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 00000000..3a27a430 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,14 @@ +include ../Makefile.settings + +LFLAGS +=-lcheck + +all: check + ./check + +check: check.o check_util.o ../util.o + @echo '*' Linking $@ + @$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(EFLAGS) + +%.o: %.c + @echo '*' Compiling $< + @$(CC) -c $(CFLAGS) $< -o $@ diff --git a/tests/check.c b/tests/check.c new file mode 100644 index 00000000..999da16a --- /dev/null +++ b/tests/check.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +/* From check_util.c */ +Suite *util_suite(void); + +int main (void) +{ + int nf; + SRunner *sr = srunner_create(util_suite()); + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/tests/check_util.c b/tests/check_util.c new file mode 100644 index 00000000..52e8174c --- /dev/null +++ b/tests/check_util.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include "irc.h" +#include "set.h" +#include "util.h" + +START_TEST(test_strip_linefeed) +{ + int i; + const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; + const char *expected[] = { "Test", "Test", "TestX", NULL }; + + for (i = 0; get[i]; i++) { + char copy[20]; + strcpy(copy, get[i]); + strip_linefeed(copy); + fail_unless (strcmp(copy, expected[i]) == 0, + "(%d) strip_linefeed broken: %s -> %s (expected: %s)", + i, get[i], copy, expected[i]); + } +} +END_TEST + +Suite *util_suite (void) +{ + Suite *s = suite_create("Util"); + TCase *tc_core = tcase_create("Core"); + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, test_strip_linefeed); + return s; +} -- cgit v1.2.3 From 1fc2958b1e503b782081692c1a503bc7bba19fe1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Jun 2006 14:07:51 +0200 Subject: Add checks for nick functions as well, fix bug where nick lengths weren't being honored. --- nick.c | 4 ++-- tests/Makefile | 4 +++- tests/check.c | 15 ++++++++++++ tests/check_nick.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/check_util.c | 19 +++++++++++++++ 5 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 tests/check_nick.c diff --git a/nick.c b/nick.c index 771d2288..68dd9802 100644 --- a/nick.c +++ b/nick.c @@ -162,7 +162,7 @@ void nick_strip( char * nick ) { int i, j; - for( i = j = 0; nick[i] && i < MAX_NICK_LENGTH; i++ ) + for( i = j = 0; nick[i] && j < MAX_NICK_LENGTH; i++ ) { if( strchr( nick_lc_chars, nick[i] ) || strchr( nick_uc_chars, nick[i] ) ) @@ -171,7 +171,7 @@ void nick_strip( char * nick ) j++; } } - while( j < MAX_NICK_LENGTH ) + while( j <= MAX_NICK_LENGTH ) nick[j++] = '\0'; } diff --git a/tests/Makefile b/tests/Makefile index 3a27a430..ce8ed690 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,7 +5,9 @@ LFLAGS +=-lcheck all: check ./check -check: check.o check_util.o ../util.o +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 + +check: check.o check_util.o check_nick.o $(addprefix ../, $(main_objs)) ../protocols/protocols.o @echo '*' Linking $@ @$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS) $(EFLAGS) diff --git a/tests/check.c b/tests/check.c index 999da16a..5cfb7dfd 100644 --- a/tests/check.c +++ b/tests/check.c @@ -2,14 +2,29 @@ #include #include #include +#include "bitlbee.h" + +global_t global; /* Against global namespace pollution */ + +double gettime() +{ + struct timeval time[1]; + + gettimeofday( time, 0 ); + return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); +} /* From check_util.c */ Suite *util_suite(void); +/* From check_nick.c */ +Suite *nick_suite(void); + int main (void) { int nf; SRunner *sr = srunner_create(util_suite()); + srunner_add_suite(sr, nick_suite()); srunner_run_all (sr, CK_NORMAL); nf = srunner_ntests_failed(sr); srunner_free(sr); diff --git a/tests/check_nick.c b/tests/check_nick.c new file mode 100644 index 00000000..5858e512 --- /dev/null +++ b/tests/check_nick.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include "irc.h" +#include "set.h" +#include "util.h" + +START_TEST(test_nick_strip) +{ + int i; + const char *get[] = { "test:", "test", "test\n", + "thisisaveryveryveryverylongnick", + "thisisave:ryveryveryverylongnick", + "t::::est", + NULL }; + const char *expected[] = { "test", "test", "test", + "thisisaveryveryveryveryl", + "thisisaveryveryveryveryl", + "test", + NULL }; + + for (i = 0; get[i]; i++) { + char copy[30]; + strcpy(copy, get[i]); + nick_strip(copy); + fail_unless (strcmp(copy, expected[i]) == 0, + "(%d) nick_strip broken: %s -> %s (expected: %s)", + i, get[i], copy, expected[i]); + } +} +END_TEST + +START_TEST(test_nick_ok_ok) +{ + const char *nicks[] = { "foo", "bar", "bla[", "blie]", + "BreEZaH", "\\od^~", NULL }; + int i; + + for (i = 0; nicks[i]; i++) { + fail_unless (nick_ok(nicks[i]) == 1, + "nick_ok() failed: %s", nicks[i]); + } +} +END_TEST + +START_TEST(test_nick_ok_notok) +{ + const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick", + "\nillegalchar", "", "nick%", NULL }; + int i; + + for (i = 0; nicks[i]; i++) { + fail_unless (nick_ok(nicks[i]) == 0, + "nick_ok() succeeded for invalid: %s", nicks[i]); + } +} +END_TEST + +Suite *nick_suite (void) +{ + Suite *s = suite_create("Nick"); + TCase *tc_core = tcase_create("Core"); + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, test_nick_ok_ok); + tcase_add_test (tc_core, test_nick_ok_notok); + tcase_add_test (tc_core, test_nick_strip); + return s; +} diff --git a/tests/check_util.c b/tests/check_util.c index 52e8174c..e771238f 100644 --- a/tests/check_util.c +++ b/tests/check_util.c @@ -24,11 +24,30 @@ START_TEST(test_strip_linefeed) } END_TEST +START_TEST(test_strip_newlines) +{ + int i; + const char *get[] = { "Test", "Test\r\n", "Test\nX\n", NULL }; + const char *expected[] = { "Test", "Test ", "Test X ", NULL }; + + for (i = 0; get[i]; i++) { + char copy[20], *ret; + strcpy(copy, get[i]); + ret = strip_newlines(copy); + fail_unless (strcmp(copy, expected[i]) == 0, + "(%d) strip_newlines broken: %s -> %s (expected: %s)", + i, get[i], copy, expected[i]); + fail_unless (copy == ret, "Original string not returned"); + } +} +END_TEST + Suite *util_suite (void) { Suite *s = suite_create("Util"); TCase *tc_core = tcase_create("Core"); suite_add_tcase (s, tc_core); tcase_add_test (tc_core, test_strip_linefeed); + tcase_add_test (tc_core, test_strip_newlines); return s; } -- cgit v1.2.3 From 59f5c42a86fe73e95aaed0bfe455c7c816f39d2b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Wed, 21 Jun 2006 18:56:16 +0200 Subject: Fixed md->grouplist memory leak. --- protocols/msn/msn.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c index bac9c427..6393f31d 100644 --- a/protocols/msn/msn.c +++ b/protocols/msn/msn.c @@ -94,6 +94,8 @@ static void msn_close( struct gaim_connection *gc ) g_slist_free( md->msgq ); } + g_free( md->grouplist ); + g_free( md ); } -- cgit v1.2.3 From 4b1a75af236ad968346749d6115c785b74126f85 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 25 Jun 2006 17:16:44 +0200 Subject: Disabling call to sethostent() because it causes major problems on OpenBSD (and because I don't see any use for it anyway). --- protocols/proxy.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/protocols/proxy.c b/protocols/proxy.c index b8aa304d..70a2158d 100644 --- a/protocols/proxy.c +++ b/protocols/proxy.c @@ -537,10 +537,6 @@ int proxy_connect(const char *host, int port, b_event_handler func, gpointer dat phb->func = func; phb->data = data; -#ifndef _WIN32 - sethostent(1); -#endif - if ((proxytype == PROXY_NONE) || !proxyhost || !proxyhost[0] || !proxyport || (proxyport == -1)) return proxy_connect_none(host, port, phb); else if (proxytype == PROXY_HTTP) -- cgit v1.2.3 From 38cc9d4d7a994e4c6b2fc76897591c70e9c14b99 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 25 Jun 2006 18:40:00 +0200 Subject: Fixed a memory leak (u->group). --- user.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/user.c b/user.c index b412a42d..5f0952f5 100644 --- a/user.c +++ b/user.c @@ -105,9 +105,10 @@ int user_del( irc_t *irc, char *nick ) if( u->nick != u->user ) g_free( u->user ); if( u->nick != u->host ) g_free( u->host ); if( u->nick != u->realname ) g_free( u->realname ); - if( u->away ) g_free( u->away ); - if( u->handle ) g_free( u->handle ); - if( u->sendbuf ) g_free( u->sendbuf ); + g_free( u->group ); + g_free( u->away ); + g_free( u->handle ); + g_free( u->sendbuf ); if( u->sendbuf_timer ) b_event_remove( u->sendbuf_timer ); g_free( u ); -- cgit v1.2.3 From 9b63df67847e72abb00246fdfc82830137153c3c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 25 Jun 2006 21:20:14 +0200 Subject: Why did I forget this one? *sigh* --- irc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc.c b/irc.c index 52b80d41..c045d12b 100644 --- a/irc.c +++ b/irc.c @@ -576,7 +576,7 @@ void irc_vawrite( irc_t *irc, char *format, va_list params ) char line[IRC_MAX_LINE+1], *cs; /* Don't try to write anything new anymore when shutting down. */ - if( irc->status == USTATUS_SHUTDOWN ) + if( irc->status & USTATUS_SHUTDOWN ) return; line[IRC_MAX_LINE] = 0; -- cgit v1.2.3