]>
Commit | Line | Data |
---|---|---|
73936902 EK |
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 | static void | |
70 | chmode_init(void) | |
71 | { | |
72 | channel = make_channel(); | |
73 | client = make_local_person(); | |
74 | } | |
75 | ||
76 | int | |
77 | main(int argc, char *argv[]) | |
78 | { | |
79 | plan_lazy(); | |
80 | ||
81 | ircd_util_init(__FILE__); | |
82 | client_util_init(); | |
83 | ||
84 | chmode_init(); | |
85 | ||
86 | test_chmode_parse(); | |
87 | ||
88 | client_util_free(); | |
89 | ircd_util_free(); | |
90 | ||
91 | return 0; | |
92 | } |