source: tests/check_irc.c @ b99296f

Last change on this file since b99296f was 18ff38f, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-03-29T23:15:04Z

Be more liberal with accepted line endings. ERC on Windows likes to use
"\r\r\n", for example, and until now BitlBee only chopped off the \r\n,
leaving the first \r as part of the command, which means it couldn't log
in to BitlBee at all. (Bad character in nickname.)

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[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
10START_TEST(test_connect)
11        GIOChannel *ch1, *ch2;
12        irc_t *irc;
13        char *raw;
14        fail_unless(g_io_channel_pair(&ch1, &ch2));
15
16        irc = irc_new(g_io_channel_unix_get_fd(ch1));
17
18        irc_free(irc);
19
20        fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
21       
22        fail_if(strcmp(raw, "") != 0);
23
24        g_free(raw);
25END_TEST
26
27START_TEST(test_login)
28        GIOChannel *ch1, *ch2;
29        irc_t *irc;
30        GError *error = NULL;
31        char *raw;
32        fail_unless(g_io_channel_pair(&ch1, &ch2));
33
34        g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
35        g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL);
36
37        irc = irc_new(g_io_channel_unix_get_fd(ch1));
38
[18ff38f]39        fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n"
40                        "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
[7bcdde3]41        fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
42
43        g_main_iteration(FALSE);
44        irc_free(irc);
45
46        fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
47       
48        fail_unless(strstr(raw, "001") != NULL);
49        fail_unless(strstr(raw, "002") != NULL);
50        fail_unless(strstr(raw, "003") != NULL);
51        fail_unless(strstr(raw, "004") != NULL);
52        fail_unless(strstr(raw, "005") != NULL);
53
54        g_free(raw);
55END_TEST
56
57Suite *irc_suite (void)
58{
59        Suite *s = suite_create("IRC");
60        TCase *tc_core = tcase_create("Core");
61        suite_add_tcase (s, tc_core);
62        tcase_add_test (tc_core, test_connect);
63        tcase_add_test (tc_core, test_login);
64        return s;
65}
Note: See TracBrowser for help on using the repository browser.