Merge fix for logging of mode changes by charly.
[jelmer/ctrlproxy.git] / testsuite / test-networkinfo.c
1 /*
2     ircdtorture: an IRC RFC compliancy tester
3         (c) 2007 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 <stdbool.h>
25 #include "torture.h"
26
27 START_TEST(test_is_prefix)
28         struct irc_network_info info;
29         memset(&info, 0, sizeof(info));
30         network_info_parse(&info, "PREFIX=(qaohv)~&@%+");
31         fail_unless(is_prefix('&', &info));
32         fail_if(is_prefix(' ', &info));
33         network_info_parse(&info, "PREFIX=");
34         fail_if(is_prefix('&', &info));
35 END_TEST
36
37 START_TEST(test_get_prefix_by_mode)
38         struct irc_network_info info;
39         memset(&info, 0, sizeof(info));
40         network_info_parse(&info, "PREFIX=(qaohv)~&@%+");
41         fail_unless(get_prefix_by_mode('a', &info) == '&');
42         fail_unless(get_prefix_by_mode('q', &info) == '~');
43         fail_unless(get_prefix_by_mode('h', &info) == '%');
44         fail_unless(get_prefix_by_mode('!', &info) == ' ');
45         network_info_parse(&info, "PREFIX=(qaohv~&@%+");
46         fail_unless(get_prefix_by_mode('a', &info) == '&');
47 END_TEST
48
49 START_TEST(test_get_charset)
50         struct irc_network_info info;
51         memset(&info, 0, sizeof(info));
52         network_info_parse(&info, "CHARSET=ascii");
53         fail_unless(!strcmp(get_charset(&info), "ascii"));
54 END_TEST
55
56 START_TEST(test_get_charset_default)
57         struct irc_network_info *info;
58         info = network_info_init();
59         fail_unless(get_charset(info) == NULL);
60 END_TEST
61
62 START_TEST(test_chanmode_type_default)
63         fail_unless(network_chanmode_type('I', NULL) == CHANMODE_NICKLIST);
64         fail_unless(network_chanmode_type('k', NULL) == CHANMODE_SETTING);
65         fail_unless(network_chanmode_type('z', NULL) == CHANMODE_UNKNOWN);
66         fail_unless(network_chanmode_type('m', NULL) == CHANMODE_BOOL);
67         fail_unless(network_chanmode_type('l', NULL) == CHANMODE_OPT_SETTING);
68 END_TEST
69
70 START_TEST(test_chanmode_type_lookup)
71         struct irc_network_info ni;
72         memset(&ni, 0, sizeof(ni));
73         network_info_parse(&ni, "CHANMODES=b,k,l,ciLmMnOprRst");
74         fail_unless(network_chanmode_type('I', &ni) == CHANMODE_UNKNOWN);
75         fail_unless(network_chanmode_type('k', &ni) == CHANMODE_SETTING);
76         fail_unless(network_chanmode_type('z', &ni) == CHANMODE_UNKNOWN);
77         fail_unless(network_chanmode_type('m', &ni) == CHANMODE_BOOL);
78         fail_unless(network_chanmode_type('l', &ni) == CHANMODE_OPT_SETTING);
79         fail_unless(network_chanmode_type('w', &ni) == CHANMODE_UNKNOWN);
80 END_TEST
81
82 Suite *networkinfo_suite()
83 {
84         Suite *s = suite_create("networkinfo");
85         TCase *tc_core = tcase_create("core");
86         suite_add_tcase(s, tc_core);
87         tcase_add_test(tc_core, test_is_prefix);
88         tcase_add_test(tc_core, test_get_prefix_by_mode);
89         tcase_add_test(tc_core, test_get_charset);
90         tcase_add_test(tc_core, test_get_charset_default);
91         tcase_add_test(tc_core, test_chanmode_type_default);
92         tcase_add_test(tc_core, test_chanmode_type_lookup);
93         return s;
94 }