]> jfr.im git - solanum.git/blob - tests/chmode1.c
listener: refactor to use rb_dlink like the other lists in ircd
[solanum.git] / tests / chmode1.c
1 /*
2 * Copyright 2020 Ed Kellett
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 * USA
18 */
19
20 #include <stdinc.h>
21 #include <channel.h>
22 #include <hook.h>
23
24 #include "client_util.h"
25 #include "ircd_util.h"
26 #include "tap/basic.h"
27
28 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
29
30 static struct Channel *channel;
31 static struct Client *client;
32
33 static hook_data_channel_approval chmode_hdata;
34
35 static void
36 chmode_access_hook(void *data_)
37 {
38 hook_data_channel_approval *data = data_;
39 chmode_hdata = *data;
40 }
41
42 void
43 test_chmode_parse(void)
44 {
45 add_hook_prio("get_channel_access", chmode_access_hook, HOOK_MONITOR);
46
47 set_channel_mode(client, client, channel, NULL, 2, (const char *[]){"o", "foo"});
48 is_string("+o foo", chmode_hdata.modestr, MSG);
49
50 set_channel_mode(client, client, channel, NULL, 3, (const char *[]){"o", "foo", "bar"});
51 is_string("+o foo", chmode_hdata.modestr, MSG);
52
53 chmode_hdata.modestr = NULL;
54 set_channel_mode(client, client, channel, NULL, 3, (const char *[]){"+-=+++--+", "foo", "bar"});
55 is_bool(true, chmode_hdata.modestr == NULL, MSG);
56
57 set_channel_mode(client, client, channel, NULL, 1, (const char *[]){"b"});
58 is_string("=b", chmode_hdata.modestr, MSG);
59
60 set_channel_mode(client, client, channel, NULL, 2, (const char *[]){"bb", "foo"});
61 is_string("+b=b foo", chmode_hdata.modestr, MSG);
62
63 set_channel_mode(client, client, channel, NULL, 1, (const char *[]){"iqiqiqiq"});
64 is_string("+i=q+i=q+i=q+i=q", chmode_hdata.modestr, MSG);
65
66 remove_hook("get_channel_access", chmode_access_hook);
67 }
68
69 void
70 test_chmode_limits(void)
71 {
72 char chmode_buf[2 + MAXMODEPARAMS + 1] = "+";
73 const char *chmode_parv[1 + MAXMODEPARAMS + 1] = { chmode_buf };
74 add_hook_prio("get_channel_access", chmode_access_hook, HOOK_MONITOR);
75
76 for (size_t i = 0; i < MAXMODEPARAMS + 1; i++)
77 {
78 chmode_buf[i + 1] = 'l';
79 chmode_parv[i + 1] = "7";
80 }
81
82 set_channel_mode(client, client, channel, NULL, 1 + MAXMODEPARAMS + 1, chmode_parv);
83
84 is_int('+', chmode_hdata.modestr[0], MSG);
85
86 for (size_t i = 0; i < MAXMODEPARAMS; i++)
87 {
88 is_int('l', chmode_hdata.modestr[i + 1], MSG);
89 }
90
91 is_int(' ', chmode_hdata.modestr[MAXMODEPARAMS + 1], MSG);
92
93 for (size_t i = 0; i < MAXMODEPARAMS; i++)
94 {
95 is_int(' ', chmode_hdata.modestr[MAXMODEPARAMS + 1 + i * 2], MSG);
96 is_int('7', chmode_hdata.modestr[MAXMODEPARAMS + 2 + i * 2], MSG);
97 }
98
99 is_int('\0', chmode_hdata.modestr[MAXMODEPARAMS * 3 + 1], MSG);
100
101 remove_hook("get_channel_access", chmode_access_hook);
102 }
103
104 static void
105 chmode_init(void)
106 {
107 channel = make_channel();
108 client = make_local_person();
109 }
110
111 int
112 main(int argc, char *argv[])
113 {
114 plan_lazy();
115
116 ircd_util_init(__FILE__);
117 client_util_init();
118
119 chmode_init();
120
121 test_chmode_parse();
122 test_chmode_limits();
123
124 client_util_free();
125 ircd_util_free();
126
127 return 0;
128 }