1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
test-irc.c : irssi
Copyright (C) 2017 Will Storey
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <glib.h>
#include <irssi/src/irc/core/irc.h>
#include <string.h>
typedef struct {
char const *const description;
char const *const input;
char const *const input_after;
char const *const output;
} event_get_param_test_case;
event_get_param_test_case const event_get_param_fixtures[] = {
{
.description = "Zero parameters",
.input = "",
.input_after = "",
.output = "",
},
{
.description = "One parameter",
.input = "#test",
.input_after = "",
.output = "#test",
},
{
.description = "One parameter, trailing space",
.input = "#test ",
.input_after = "",
.output = "#test",
},
{
.description = "One parameter, more trailing space",
.input = "#test ",
.input_after = " ",
.output = "#test",
},
{
.description = "Two parameters",
.input = "#test +o",
.input_after = "+o",
.output = "#test",
},
{
.description = "Two parameters continued",
.input = "+o",
.input_after = "",
.output = "+o",
},
{
.description = "Two parameters with trailing space",
.input = "#test +o ",
.input_after = "+o ",
.output = "#test",
},
{
.description = "Two parameters with trailing space continued",
.input = "+o ",
.input_after = "",
.output = "+o",
},
{
.description = "Two parameters with inline and trailing space",
.input = "#test +o ",
.input_after = " +o ",
.output = "#test",
},
/* TODO: It seems not ideal that the caller has to deal with inline space.
*/
{
.description = "Two parameters with inline and trailing space continued",
.input = " +o ",
.input_after = "+o ",
.output = "",
},
};
static void test_event_get_param(const event_get_param_test_case *test);
typedef struct {
char const *const description;
char const *const input;
char const *const output0;
char const *const output1;
} event_get_params_test_case;
event_get_params_test_case const event_get_params_fixtures[] = {
{
.description = "Only a channel",
.input = "#test",
.output0 = "#test",
.output1 = "",
},
{
.description = "Only a channel with trailing space",
.input = "#test ",
.output0 = "#test",
.output1 = "",
},
{
.description = "No :<trailing>, channel mode with one parameter after channel name",
.input = "#test +i",
.output0 = "#test",
.output1 = "+i",
},
{
.description = "No :<trailing>, channel mode with two parameters after channel name",
.input = "#test +o tester",
.output0 = "#test",
.output1 = "+o tester",
},
{
.description = "No :<trailing>, channel mode with three parameters afer channel name",
.input = "#test +ov tester tester2",
.output0 = "#test",
.output1 = "+ov tester tester2",
},
{
.description = "No :<trailing>, channel mode with three parameters afer channel name, bunch of extra space",
.input = "#test +ov tester tester2 ",
.output0 = "#test",
.output1 = " +ov tester tester2 ",
},
{
.description = "Channel mode with one parameter after channel name, :<trailing> at the start of modes",
.input = "#test :+i",
.output0 = "#test",
.output1 = "+i",
},
{
.description = "Channel mode with two parameters after channel name, :<trailing> at the start of modes",
.input = "#test :+o tester",
.output0 = "#test",
.output1 = "+o tester",
},
{
.description = "Channel mode with three parameters after channel name, :<trailing> at the start of modes",
.input = "#test :+ov tester tester2",
.output0 = "#test",
.output1 = "+ov tester tester2",
},
{
.description = "Channel mode with two parameters after channel name, :<trailing> on the final parameter",
.input = "#test +o :tester",
.output0 = "#test",
.output1 = "+o tester",
},
{
.description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter",
.input = "#test +ov tester :tester2",
.output0 = "#test",
.output1 = "+ov tester tester2",
},
{
.description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter, also a second : present",
.input = "#test +ov tester :tester2 hi:there",
.output0 = "#test",
.output1 = "+ov tester tester2 hi:there",
},
};
static void test_event_get_params(const event_get_params_test_case *test);
int main(int argc, char **argv)
{
int i;
g_test_init(&argc, &argv, NULL);
for (i = 0; i < G_N_ELEMENTS(event_get_params_fixtures); i++) {
char *name = g_strdup_printf("/test/event_get_params/%d", i);
g_test_add_data_func(name, &event_get_params_fixtures[i], (GTestDataFunc)test_event_get_params);
g_free(name);
}
for (i = 0; i < G_N_ELEMENTS(event_get_param_fixtures); i++) {
char *name = g_strdup_printf("/test/event_get_param/%d", i);
g_test_add_data_func(name, &event_get_param_fixtures[i], (GTestDataFunc)test_event_get_param);
g_free(name);
}
#if GLIB_CHECK_VERSION(2,38,0)
g_test_set_nonfatal_assertions();
#endif
return g_test_run();
}
static void test_event_get_param(const event_get_param_test_case *test)
{
char *buf, *input, *output;
input = buf = g_strdup(test->input);
output = event_get_param(&input);
g_assert_cmpstr(input, ==, test->input_after);
g_assert_cmpstr(output, ==, test->output);
g_free(buf);
}
static void test_event_get_params(const event_get_params_test_case *test)
{
char *output0, *output1, *params;
output0 = NULL;
output1 = NULL;
params = event_get_params(test->input, 2 | PARAM_FLAG_GETREST,
&output0, &output1);
/* params happens to always point at the first output */
g_assert_cmpstr(params, ==, test->output0);
g_assert_cmpstr(output0, ==, test->output0);
g_assert_cmpstr(output1, ==, test->output1);
g_free(params);
}
|