aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-12-06 14:57:25 +0100
committerJelmer Vernooij <jelmer@samba.org>2006-12-06 14:57:25 +0100
commit7bcdde3d31f0e5b53601b90aa33ebd820c770172 (patch)
tree7288db8728fca1f9615822b71d745466ad69855e /tests
parent3b4cc8f0af7a4d9e1fae69e12a438b15f9206003 (diff)
Some simple tests for irc_*()
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile4
-rw-r--r--tests/check.c15
-rw-r--r--tests/check_irc.c65
3 files changed, 82 insertions, 2 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 6a97e8ac..9dd3df7c 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -3,14 +3,14 @@ include ../Makefile.settings
LFLAGS +=-lcheck
all: check
- ./check
+ ./check $(CHECKFLAGS)
clean:
rm -f check *.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
+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 $@
diff --git a/tests/check.c b/tests/check.c
index 6cba4302..42ff067f 100644
--- a/tests/check.c
+++ b/tests/check.c
@@ -37,6 +37,9 @@ Suite *nick_suite(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;
@@ -59,10 +62,22 @@ int main (int argc, char **argv)
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_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);
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;
+}