diff options
-rw-r--r-- | help.c | 13 | ||||
-rw-r--r-- | help.h | 2 | ||||
-rw-r--r-- | tests/Makefile | 2 | ||||
-rw-r--r-- | tests/check.c | 4 | ||||
-rw-r--r-- | tests/check_help.c | 30 | ||||
-rw-r--r-- | unix.c | 2 |
6 files changed, 43 insertions, 10 deletions
@@ -30,7 +30,7 @@ #define BUFSIZE 1100 -help_t *help_init( help_t **help ) +help_t *help_init( help_t **help, const char *helpfile ) { int i, buflen = 0; help_t *h; @@ -40,7 +40,7 @@ help_t *help_init( help_t **help ) *help = h = g_new0 ( help_t, 1 ); - h->fd = open( global.helpfile, O_RDONLY + h->fd = open( helpfile, O_RDONLY #ifdef _WIN32 | O_BINARY #endif @@ -108,12 +108,11 @@ char *help_get( help_t **help, char *string ) struct stat stat[1]; help_t *h; - h=*help; - - while( h ) + for( h = *help; h; h = h->next ) { - if( g_strcasecmp( h->string, string ) == 0 ) break; - h = h->next; + if( h->string != NULL && + g_strcasecmp( h->string, string ) == 0 ) + break; } if( h && h->length > 0 ) { @@ -42,7 +42,7 @@ typedef struct help struct help *next; } help_t; -help_t *help_init( help_t **help ); +help_t *help_init( help_t **help, const char *helpfile ); char *help_get( help_t **help, char *string ); #endif diff --git a/tests/Makefile b/tests/Makefile index 9dd3df7c..3ddd1570 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -10,7 +10,7 @@ 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_irc.o +test_objs = check.o check_util.o check_nick.o check_md5.o check_irc.o check_help.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 f70ccae7..069b3c57 100644 --- a/tests/check.c +++ b/tests/check.c @@ -40,6 +40,9 @@ Suite *md5_suite(void); /* From check_irc.c */ Suite *irc_suite(void); +/* From check_help.c */ +Suite *help_suite(void); + int main (int argc, char **argv) { int nf; @@ -80,6 +83,7 @@ int main (int argc, char **argv) srunner_add_suite(sr, nick_suite()); srunner_add_suite(sr, md5_suite()); srunner_add_suite(sr, irc_suite()); + srunner_add_suite(sr, help_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_help.c b/tests/check_help.c new file mode 100644 index 00000000..7e5283e3 --- /dev/null +++ b/tests/check_help.c @@ -0,0 +1,30 @@ +#include <stdlib.h> +#include <glib.h> +#include <gmodule.h> +#include <check.h> +#include <string.h> +#include <stdio.h> +#include "help.h" + +START_TEST(test_help_none) + help_t *h, *r; + r = help_init(&h, "/dev/null"); + fail_if(r == NULL); + fail_if(r != h); +END_TEST + +START_TEST(test_help_nonexistent) + help_t *h, *r; + r = help_init(&h, "/dev/null"); + fail_unless(help_get(&h, "nonexistent") == NULL); +END_TEST + +Suite *help_suite (void) +{ + Suite *s = suite_create("Help"); + TCase *tc_core = tcase_create("Core"); + suite_add_tcase (s, tc_core); + tcase_add_test (tc_core, test_help_none); + tcase_add_test (tc_core, test_help_nonexistent); + return s; +} @@ -111,7 +111,7 @@ int main( int argc, char *argv[], char **envp ) if( !getuid() || !geteuid() ) log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); - if( help_init( &(global.help) ) == NULL ) + if( help_init( &(global.help), global.helpfile ) == NULL ) log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); b_main_run(); |