2 ircdtorture: an IRC RFC compliancy tester
3 (c) 2006 Jelmer Vernooij <jelmer@nl.linux.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "ctrlproxy.h"
25 #include "internals.h"
27 START_TEST(test_create_no_network)
28 GIOChannel *ch = g_io_channel_unix_new(0);
29 client_init_iochannel(NULL, ch, "desc");
32 START_TEST(test_create_introduction)
33 GIOChannel *ch1, *ch2;
34 g_io_channel_pair(&ch1, &ch2);
35 client_init_iochannel(NULL, ch1, "desc");
38 START_TEST(test_network_first)
39 GIOChannel *ch1, *ch2;
42 g_io_channel_pair(&ch1, &ch2);
43 c = client_init_iochannel(NULL, ch1, "desc");
44 g_io_channel_unref(ch1);
45 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
46 "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
47 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
48 g_main_iteration(FALSE);
49 g_main_iteration(FALSE);
50 g_main_iteration(FALSE);
51 g_io_channel_read_to_end(ch2, &raw, NULL, NULL);
52 fail_unless(!strcmp(raw, "ERROR :Please select a network first, or specify one in your configuration file\r\n"), "Got: %s", raw);
56 START_TEST(test_login)
57 GIOChannel *ch1, *ch2;
59 struct global *g = TORTURE_GLOBAL;
60 struct irc_network_info ni = { };
61 struct irc_network n = {
66 g_io_channel_pair(&ch1, &ch2);
67 c = client_init_iochannel(&n, ch1, "desc");
68 g_io_channel_unref(ch1);
69 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
70 "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
71 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
72 fail_unless(g_io_channel_flush(ch1, NULL) == G_IO_STATUS_NORMAL);
73 g_main_iteration(FALSE);
74 fail_if(c->state == NULL);
75 fail_if(c->state->me.nick == NULL);
76 fail_unless(!strcmp(c->state->me.nick, "bla"));
79 START_TEST(test_read_nonutf8)
80 GIOChannel *ch1, *ch2;
82 struct global *g = TORTURE_GLOBAL;
83 struct irc_network_info ni = { .name = "test" };
84 struct irc_network n = {
88 g_io_channel_pair(&ch1, &ch2);
89 c = client_init_iochannel(&n, ch1, "desc");
90 g_io_channel_unref(ch1);
91 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
93 "PRIVMSG foo :èeeé\\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
94 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
95 g_main_iteration(FALSE);
96 fail_if(c->state->me.nick == NULL);
97 fail_unless(!strcmp(c->state->me.nick, "bla"));
98 client_send_args(c, "PRIVMSG", "foo", "\x024:öéé", NULL);
103 START_TEST(test_disconnect)
104 GIOChannel *ch1, *ch2;
105 struct irc_client *client;
107 GError *error = NULL;
109 g_io_channel_pair(&ch1, &ch2);
110 client = client_init_iochannel(NULL, ch1, "desc");
111 g_io_channel_unref(ch1);
112 client_disconnect(client, "Because");
113 g_main_iteration(FALSE);
114 g_main_iteration(FALSE);
115 g_io_channel_read_to_end(ch2, &raw, &length, &error);
116 fail_unless(!strcmp(raw, "ERROR :Because\r\n"));
119 START_TEST(test_replace_hostmask)
120 struct irc_line *nl, *l;
121 struct network_nick old = {
123 .hostname = "foohost",
124 .username = "foouser",
125 .hostmask = "foo!foouser@foohost"
127 struct network_nick new = {
129 .hostname = "barhost",
130 .username = "baruser",
131 .hostmask = "foo!baruser@barhost"
133 l = irc_parse_line(":foo!foouser@foohost JOIN #bar");
134 fail_unless(NULL == irc_line_replace_hostmask(l, NULL, &old, &old));
135 nl = irc_line_replace_hostmask(l, NULL, &old, &new);
137 fail_unless(!strcmp(irc_line_string(nl), ":foo!baruser@barhost JOIN #bar"));
138 l = irc_parse_line(":bar!lala@host JOIN #bar");
139 fail_unless(NULL == irc_line_replace_hostmask(l, NULL, &old, &new));
140 l = irc_parse_line(":server 302 foo :unused=+unused@host foo=+foouser@foohost");
141 nl = irc_line_replace_hostmask(l, NULL, &old, &new);
143 fail_unless(!strcmp(irc_line_string(nl), ":server 302 foo :unused=+unused@host foo=+baruser@barhost"), "was %s", irc_line_string(nl));
144 l = irc_parse_line(":server 311 foo foo foouser foohost :someinfo");
145 nl = irc_line_replace_hostmask(l, NULL, &old, &new);
147 fail_unless(!strcmp(irc_line_string(nl), ":server 311 foo foo baruser barhost :someinfo"), "was %s", irc_line_string(nl));
148 l = irc_parse_line("NOTICE * boe");
149 nl = irc_line_replace_hostmask(l, NULL, &old, &new);
150 fail_unless(nl == NULL);
153 START_TEST(test_login_nonetwork)
154 GIOChannel *ch1, *ch2;
155 struct irc_client *c;
156 g_io_channel_pair(&ch1, &ch2);
157 c = client_init_iochannel(NULL, ch1, "desc");
158 g_io_channel_unref(ch1);
159 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
160 "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
161 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
162 g_main_iteration(FALSE);
163 fail_if(c->state->me.nick == NULL);
168 Suite *client_suite()
170 Suite *s = suite_create("client");
171 TCase *tc_core = tcase_create("core");
172 suite_add_tcase(s, tc_core);
173 tcase_add_test(tc_core, test_create_no_network);
174 tcase_add_test(tc_core, test_create_introduction);
175 tcase_add_test(tc_core, test_disconnect);
176 tcase_add_test(tc_core, test_login);
177 tcase_add_test(tc_core, test_login_nonetwork);
178 tcase_add_test(tc_core, test_network_first);
179 tcase_add_test(tc_core, test_read_nonutf8);
180 tcase_add_test(tc_core, test_replace_hostmask);