1 /*
2 ircdtorture: an IRC RFC compliancy tester
3 (c) 2006 Jelmer Vernooij <jelmer@nl.linux.org>
4
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.
9
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.
14
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.
18 */
19
20 #include "internals.h"
21 #include <stdio.h>
22 #include <string.h>
23 #include <check.h>
24 #include "torture.h"
25
26 START_TEST(test_create)
27 struct network_config nc = {
28 .name = "test"
29 };
30 struct irc_network *n;
31 n = load_network(NULL, &nc);
32 END_TEST
33
34 START_TEST(test_uncreate)
35 struct network_config nc = {
36 .name = "test"
37 };
38 struct irc_network *n;
39 n = load_network(NULL, &nc);
40 unload_network(n);
41 END_TEST
42
START_TEST(test_login)43 START_TEST(test_login)
44 GIOChannel *ch1, *ch2;
45 struct network_config nc = {
46 .name = "test",
47 .nick = g_strdup("foo"),
48 .username = g_strdup("blah"),
49 .fullname = g_strdup("bloeh "),
50 .type = NETWORK_IOCHANNEL
51 };
52 struct irc_network *n;
53 struct global *g = TORTURE_GLOBAL;
54 char *raw;
55 GError *error = NULL;
56 n = load_network(g, &nc);
57 fail_unless(n->connection.state == NETWORK_CONNECTION_STATE_NOT_CONNECTED);
58 g_io_channel_pair(&ch1, &ch2);
59 network_set_iochannel(n, ch1);
60 fail_unless(n->connection.state == NETWORK_CONNECTION_STATE_LOGIN_SENT);
61 g_io_channel_set_close_on_unref(ch1, TRUE);
62 g_io_channel_unref(ch1);
63 disconnect_network(n);
64 g_io_channel_read_to_end(ch2, &raw, NULL, &error);
65 fail_unless(error == NULL);
66 fail_unless(!strcmp(raw, "NICK foo\r\nUSER blah a a :bloeh \r\nQUIT\r\n"), raw);
67 END_TEST
68
network_suite()69 Suite *network_suite()
70 {
71 Suite *s = suite_create("network");
72 TCase *tc_core = tcase_create("core");
73 suite_add_tcase(s, tc_core);
74 tcase_add_test(tc_core, test_create);
75 tcase_add_test(tc_core, test_uncreate);
76 tcase_add_test(tc_core, test_login);
77 return s;
78 }
79