]>
jfr.im git - solanum.git/blob - tests/substitution1.c
2 * substition.c: Test substitution under various conditions
3 * Copyright 2017 Simon Arlott
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 2 of the License, or
8 * (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24 #include "tap/basic.h"
27 #include "ircd_defs.h"
29 #include "substitution.h"
31 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
34 static char tmp
[2048];
35 static const char text
[] =
36 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
37 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
38 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
39 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
40 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
41 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
42 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
43 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
44 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
45 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
48 #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
50 static rb_dlink_list varlist
= { NULL
, NULL
, 0 };
51 static rb_dlink_list varlist2
= { NULL
, NULL
, 0 };
53 static void valid_variable1(void)
55 is_string("TEST1", substitution_parse("${test1}", &varlist
), MSG
);
58 static void valid_variable2(void)
60 is_string("TEST1TEST5", substitution_parse("${test1}${test5}", &varlist
), MSG
);
63 static void missing_variable1(void)
65 is_string("", substitution_parse("${test6}", &varlist
), MSG
);
68 static void missing_variable2(void)
70 is_string("", substitution_parse("${test6}${test7}", &varlist
), MSG
);
73 static void unterminated_variable1a(void)
75 is_string("TEST2", substitution_parse("${test2", &varlist
), MSG
);
78 static void unterminated_variable1b(void)
80 is_string("TEST2", substitution_parse("${test2\0${test8", &varlist
), MSG
);
83 static void unterminated_variable2a(void)
85 is_string("TEST3TEST4", substitution_parse("${test3${test4", &varlist
), MSG
);
88 static void unterminated_variable2b(void)
90 is_string("TEST3TEST4", substitution_parse("${test3${test4\0${test9", &varlist
), MSG
);
93 static void unterminated_missing_variable1(void)
95 is_string("", substitution_parse("${test6", &varlist
), MSG
);
98 static void unterminated_missing_variable2(void)
100 is_string("", substitution_parse("${test6${test7", &varlist
), MSG
);
103 static void empty_variable1(void)
105 is_string("", substitution_parse("${}", &varlist
), MSG
);
108 static void empty_variable2(void)
110 is_string("}", substitution_parse("${${}}", &varlist
), MSG
);
113 static void empty_unterminated_variable1(void)
115 is_string("", substitution_parse("${", &varlist
), MSG
);
118 static void empty_unterminated_variable2(void)
120 is_string("", substitution_parse("${${", &varlist
), MSG
);
123 static void long_variable1a(void) {
124 is_int(512, BUFSIZE
, MSG
);
125 is_string(MKTEXT(510), substitution_parse("${text510}", &varlist2
), MSG
);
128 static void long_variable1b(void) {
129 is_int(512, BUFSIZE
, MSG
);
130 is_string(MKTEXT(511), substitution_parse("${text511}", &varlist2
), MSG
);
133 static void too_long_variable1a(void) {
136 strcpy(tmp2
, MKTEXT(512));
137 tmp2
[511] = 0; /* text will be truncated to 511 chars */
139 is_int(512, BUFSIZE
, MSG
);
140 is_string(tmp2
, substitution_parse("${text512}", &varlist2
), MSG
);
143 static void too_long_variable1b(void) {
146 strcpy(tmp2
, MKTEXT(513));
147 tmp2
[511] = 0; /* text will be truncated to 511 chars */
149 is_int(512, BUFSIZE
, MSG
);
150 is_string(tmp2
, substitution_parse("${text513}", &varlist2
), MSG
);
153 static void too_long_variable1c(void) {
156 strcpy(tmp2
, MKTEXT(600));
157 tmp2
[511] = 0; /* text will be truncated to 511 chars */
159 is_int(512, BUFSIZE
, MSG
);
160 is_string(tmp2
, substitution_parse("${text600}", &varlist2
), MSG
);
163 static void long_variable2a(void) {
166 strcpy(tmp2
, MKTEXT(500));
167 strcat(tmp2
, MKTEXT(10));
169 is_int(512, BUFSIZE
, MSG
);
170 is_string(tmp2
, substitution_parse("${text500}${text10}", &varlist2
), MSG
);
173 static void long_variable2b(void) {
176 strcpy(tmp2
, MKTEXT(500));
177 strcat(tmp2
, MKTEXT(11));
179 is_int(512, BUFSIZE
, MSG
);
180 is_string(tmp2
, substitution_parse("${text500}${text11}", &varlist2
), MSG
);
183 static void too_long_variable2a(void) {
186 strcpy(tmp2
, MKTEXT(500));
187 strcat(tmp2
, MKTEXT(12));
188 tmp2
[511] = 0; /* text will be truncated to 511 chars */
190 is_int(512, BUFSIZE
, MSG
);
191 is_string(tmp2
, substitution_parse("${text500}${text12}", &varlist2
), MSG
);
194 static void too_long_variable2b(void) {
197 strcpy(tmp2
, MKTEXT(500));
198 strcat(tmp2
, MKTEXT(13));
199 tmp2
[511] = 0; /* text will be truncated to 511 chars */
201 is_int(512, BUFSIZE
, MSG
);
202 is_string(tmp2
, substitution_parse("${text500}${text13}", &varlist2
), MSG
);
205 static void too_long_variable2c(void) {
208 strcpy(tmp2
, MKTEXT(600));
209 strcat(tmp2
, MKTEXT(10));
210 tmp2
[511] = 0; /* text will be truncated to 511 chars */
212 is_int(512, BUFSIZE
, MSG
);
213 is_string(tmp2
, substitution_parse("${text600}${text10}", &varlist2
), MSG
);
216 static void long_variable3a(void) {
219 strcpy(tmp2
, MKTEXT(100));
220 strcat(tmp2
, MKTEXT(400));
221 strcat(tmp2
, MKTEXT(10));
223 is_int(512, BUFSIZE
, MSG
);
224 is_string(tmp2
, substitution_parse("${text100}${text400}${text10}", &varlist2
), MSG
);
227 static void long_variable3b(void) {
230 strcpy(tmp2
, MKTEXT(100));
231 strcat(tmp2
, MKTEXT(400));
232 strcat(tmp2
, MKTEXT(11));
234 is_int(512, BUFSIZE
, MSG
);
235 is_string(tmp2
, substitution_parse("${text100}${text400}${text11}", &varlist2
), MSG
);
238 static void too_long_variable3a(void) {
241 strcpy(tmp2
, MKTEXT(100));
242 strcat(tmp2
, MKTEXT(400));
243 strcat(tmp2
, MKTEXT(12));
244 tmp2
[511] = 0; /* text will be truncated to 511 chars */
246 is_int(512, BUFSIZE
, MSG
);
247 is_string(tmp2
, substitution_parse("${text100}${text400}${text12}", &varlist2
), MSG
);
250 static void too_long_variable3b(void) {
253 strcpy(tmp2
, MKTEXT(100));
254 strcat(tmp2
, MKTEXT(400));
255 strcat(tmp2
, MKTEXT(13));
256 tmp2
[511] = 0; /* text will be truncated to 511 chars */
258 is_int(512, BUFSIZE
, MSG
);
259 is_string(tmp2
, substitution_parse("${text100}${text400}${text13}", &varlist2
), MSG
);
262 static void too_long_variable3c(void) {
265 strcpy(tmp2
, MKTEXT(200));
266 strcat(tmp2
, MKTEXT(400));
267 strcat(tmp2
, MKTEXT(100));
268 tmp2
[511] = 0; /* text will be truncated to 511 chars */
270 is_int(512, BUFSIZE
, MSG
);
271 is_string(tmp2
, substitution_parse("${text200}${text400}${text100}", &varlist2
), MSG
);
274 int main(int argc
, char *argv
[])
276 memset(&me
, 0, sizeof(me
));
277 strcpy(me
.name
, "me.name.");
279 rb_lib_init(NULL
, NULL
, NULL
, 0, 1024, DNODE_HEAP_SIZE
, FD_HEAP_SIZE
);
280 rb_linebuf_init(LINEBUF_HEAP_SIZE
);
282 substitution_append_var(&varlist
, "testB", "TESTB");
283 substitution_append_var(&varlist
, "test1", "TEST1");
284 substitution_append_var(&varlist
, "test2", "TEST2");
285 substitution_append_var(&varlist
, "test3", "TEST3");
286 substitution_append_var(&varlist
, "test4", "TEST4");
287 substitution_append_var(&varlist
, "test5", "TEST5");
288 substitution_append_var(&varlist
, "test9", "TEST9");
289 substitution_append_var(&varlist
, "testE", "TESTE");
291 substitution_append_var(&varlist2
, "text10", MKTEXT(10));
292 substitution_append_var(&varlist2
, "text11", MKTEXT(11));
293 substitution_append_var(&varlist2
, "text12", MKTEXT(12));
294 substitution_append_var(&varlist2
, "text13", MKTEXT(13));
295 substitution_append_var(&varlist2
, "text14", MKTEXT(14));
296 substitution_append_var(&varlist2
, "text100", MKTEXT(100));
297 substitution_append_var(&varlist2
, "text200", MKTEXT(200));
298 substitution_append_var(&varlist2
, "text400", MKTEXT(400));
299 substitution_append_var(&varlist2
, "text500", MKTEXT(500));
300 substitution_append_var(&varlist2
, "text510", MKTEXT(510));
301 substitution_append_var(&varlist2
, "text511", MKTEXT(511));
302 substitution_append_var(&varlist2
, "text512", MKTEXT(512));
303 substitution_append_var(&varlist2
, "text513", MKTEXT(513));
304 substitution_append_var(&varlist2
, "text514", MKTEXT(514));
305 substitution_append_var(&varlist2
, "text600", MKTEXT(600));
313 unterminated_variable1a();
314 unterminated_variable1b();
315 unterminated_variable2a();
316 unterminated_variable2b();
317 unterminated_missing_variable1();
318 unterminated_missing_variable2();
321 empty_unterminated_variable1();
322 empty_unterminated_variable2();
330 too_long_variable1a();
331 too_long_variable1b();
332 too_long_variable1c();
333 too_long_variable2a();
334 too_long_variable2b();
335 too_long_variable2c();
336 too_long_variable3a();
337 too_long_variable3b();
338 too_long_variable3c();