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