diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-12-06 14:57:25 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2006-12-06 14:57:25 +0100 |
commit | 7bcdde3d31f0e5b53601b90aa33ebd820c770172 (patch) | |
tree | 7288db8728fca1f9615822b71d745466ad69855e /tests/check_irc.c | |
parent | 3b4cc8f0af7a4d9e1fae69e12a438b15f9206003 (diff) |
Some simple tests for irc_*()
Diffstat (limited to 'tests/check_irc.c')
-rw-r--r-- | tests/check_irc.c | 65 |
1 files changed, 65 insertions, 0 deletions
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; +} |