[7bcdde3] | 1 | #include <stdlib.h> |
---|
| 2 | #include <glib.h> |
---|
| 3 | #include <gmodule.h> |
---|
| 4 | #include <check.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | #include "irc.h" |
---|
| 8 | #include "testsuite.h" |
---|
| 9 | |
---|
| 10 | START_TEST(test_connect) |
---|
[5ebff60] | 11 | GIOChannel * ch1, *ch2; |
---|
| 12 | irc_t *irc; |
---|
| 13 | char *raw; |
---|
| 14 | fail_unless(g_io_channel_pair(&ch1, &ch2)); |
---|
[7bcdde3] | 15 | |
---|
[5ebff60] | 16 | irc = irc_new(g_io_channel_unix_get_fd(ch1)); |
---|
[7bcdde3] | 17 | |
---|
[5ebff60] | 18 | irc_free(irc); |
---|
[7bcdde3] | 19 | |
---|
[5ebff60] | 20 | fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); |
---|
[7bcdde3] | 21 | |
---|
[5ebff60] | 22 | fail_if(strcmp(raw, "") != 0); |
---|
| 23 | |
---|
| 24 | g_free(raw); |
---|
[7bcdde3] | 25 | END_TEST |
---|
| 26 | |
---|
| 27 | START_TEST(test_login) |
---|
[5ebff60] | 28 | GIOChannel * ch1, *ch2; |
---|
| 29 | irc_t *irc; |
---|
| 30 | char *raw; |
---|
| 31 | fail_unless(g_io_channel_pair(&ch1, &ch2)); |
---|
| 32 | |
---|
| 33 | g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL); |
---|
| 34 | g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL); |
---|
[7bcdde3] | 35 | |
---|
[5ebff60] | 36 | irc = irc_new(g_io_channel_unix_get_fd(ch1)); |
---|
[7bcdde3] | 37 | |
---|
[5ebff60] | 38 | fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n" |
---|
| 39 | "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); |
---|
| 40 | fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL); |
---|
[7bcdde3] | 41 | |
---|
[5ebff60] | 42 | g_main_iteration(FALSE); |
---|
| 43 | irc_free(irc); |
---|
[7bcdde3] | 44 | |
---|
[5ebff60] | 45 | fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); |
---|
[7bcdde3] | 46 | |
---|
[5ebff60] | 47 | fail_unless(strstr(raw, "001") != NULL); |
---|
| 48 | fail_unless(strstr(raw, "002") != NULL); |
---|
| 49 | fail_unless(strstr(raw, "003") != NULL); |
---|
| 50 | fail_unless(strstr(raw, "004") != NULL); |
---|
| 51 | fail_unless(strstr(raw, "005") != NULL); |
---|
[7bcdde3] | 52 | |
---|
[5ebff60] | 53 | g_free(raw); |
---|
[7bcdde3] | 54 | END_TEST |
---|
| 55 | |
---|
[5ebff60] | 56 | Suite *irc_suite(void) |
---|
[7bcdde3] | 57 | { |
---|
| 58 | Suite *s = suite_create("IRC"); |
---|
| 59 | TCase *tc_core = tcase_create("Core"); |
---|
[5ebff60] | 60 | |
---|
| 61 | suite_add_tcase(s, tc_core); |
---|
| 62 | tcase_add_test(tc_core, test_connect); |
---|
| 63 | tcase_add_test(tc_core, test_login); |
---|
[7bcdde3] | 64 | return s; |
---|
| 65 | } |
---|