]>
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 const char text
[] =
35 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
36 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
37 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
38 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
39 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
40 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
41 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
42 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
43 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
44 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
47 #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
49 static rb_dlink_list varlist
= { NULL
, NULL
, 0 };
50 static rb_dlink_list varlist2
= { NULL
, NULL
, 0 };
52 static void valid_variable1(void)
54 is_string("TEST1", substitution_parse("${test1}", &varlist
), MSG
);
57 static void valid_variable2(void)
59 is_string("TEST1TEST5", substitution_parse("${test1}${test5}", &varlist
), MSG
);
62 static void missing_variable1(void)
64 is_string("", substitution_parse("${test6}", &varlist
), MSG
);
67 static void missing_variable2(void)
69 is_string("", substitution_parse("${test6}${test7}", &varlist
), MSG
);
72 static void unterminated_variable1a(void)
74 is_string("TEST2", substitution_parse("${test2", &varlist
), MSG
);
77 static void unterminated_variable1b(void)
79 is_string("TEST2", substitution_parse("${test2\0${test8", &varlist
), MSG
);
82 static void unterminated_variable2a(void)
84 is_string("TEST3TEST4", substitution_parse("${test3${test4", &varlist
), MSG
);
87 static void unterminated_variable2b(void)
89 is_string("TEST3TEST4", substitution_parse("${test3${test4\0${test9", &varlist
), MSG
);
92 static void unterminated_missing_variable1(void)
94 is_string("", substitution_parse("${test6", &varlist
), MSG
);
97 static void unterminated_missing_variable2(void)
99 is_string("", substitution_parse("${test6${test7", &varlist
), MSG
);
102 static void empty_variable1(void)
104 is_string("", substitution_parse("${}", &varlist
), MSG
);
107 static void empty_variable2(void)
109 is_string("}", substitution_parse("${${}}", &varlist
), MSG
);
112 static void empty_unterminated_variable1(void)
114 is_string("", substitution_parse("${", &varlist
), MSG
);
117 static void empty_unterminated_variable2(void)
119 is_string("", substitution_parse("${${", &varlist
), MSG
);
122 static void long_variable1a(void) {
123 is_int(512, BUFSIZE
, MSG
);
124 is_string(MKTEXT(510), substitution_parse("${text510}", &varlist2
), MSG
);
127 static void long_variable1b(void) {
128 is_int(512, BUFSIZE
, MSG
);
129 is_string(MKTEXT(511), substitution_parse("${text511}", &varlist2
), MSG
);
132 static void too_long_variable1a(void) {
135 strcpy(tmp2
, MKTEXT(512));
136 tmp2
[511] = 0; /* text will be truncated to 511 chars */
138 is_int(512, BUFSIZE
, MSG
);
139 is_string(tmp2
, substitution_parse("${text512}", &varlist2
), MSG
);
142 static void too_long_variable1b(void) {
145 strcpy(tmp2
, MKTEXT(513));
146 tmp2
[511] = 0; /* text will be truncated to 511 chars */
148 is_int(512, BUFSIZE
, MSG
);
149 is_string(tmp2
, substitution_parse("${text513}", &varlist2
), MSG
);
152 static void too_long_variable1c(void) {
155 strcpy(tmp2
, MKTEXT(600));
156 tmp2
[511] = 0; /* text will be truncated to 511 chars */
158 is_int(512, BUFSIZE
, MSG
);
159 is_string(tmp2
, substitution_parse("${text600}", &varlist2
), MSG
);
162 static void long_variable2a(void) {
165 strcpy(tmp2
, MKTEXT(500));
166 strcat(tmp2
, MKTEXT(10));
168 is_int(512, BUFSIZE
, MSG
);
169 is_string(tmp2
, substitution_parse("${text500}${text10}", &varlist2
), MSG
);
172 static void long_variable2b(void) {
175 strcpy(tmp2
, MKTEXT(500));
176 strcat(tmp2
, MKTEXT(11));
178 is_int(512, BUFSIZE
, MSG
);
179 is_string(tmp2
, substitution_parse("${text500}${text11}", &varlist2
), MSG
);
182 static void too_long_variable2a(void) {
185 strcpy(tmp2
, MKTEXT(500));
186 strcat(tmp2
, MKTEXT(12));
187 tmp2
[511] = 0; /* text will be truncated to 511 chars */
189 is_int(512, BUFSIZE
, MSG
);
190 is_string(tmp2
, substitution_parse("${text500}${text12}", &varlist2
), MSG
);
193 static void too_long_variable2b(void) {
196 strcpy(tmp2
, MKTEXT(500));
197 strcat(tmp2
, MKTEXT(13));
198 tmp2
[511] = 0; /* text will be truncated to 511 chars */
200 is_int(512, BUFSIZE
, MSG
);
201 is_string(tmp2
, substitution_parse("${text500}${text13}", &varlist2
), MSG
);
204 static void too_long_variable2c(void) {
207 strcpy(tmp2
, MKTEXT(600));
208 strcat(tmp2
, MKTEXT(10));
209 tmp2
[511] = 0; /* text will be truncated to 511 chars */
211 is_int(512, BUFSIZE
, MSG
);
212 is_string(tmp2
, substitution_parse("${text600}${text10}", &varlist2
), MSG
);
215 static void long_variable3a(void) {
218 strcpy(tmp2
, MKTEXT(100));
219 strcat(tmp2
, MKTEXT(400));
220 strcat(tmp2
, MKTEXT(10));
222 is_int(512, BUFSIZE
, MSG
);
223 is_string(tmp2
, substitution_parse("${text100}${text400}${text10}", &varlist2
), MSG
);
226 static void long_variable3b(void) {
229 strcpy(tmp2
, MKTEXT(100));
230 strcat(tmp2
, MKTEXT(400));
231 strcat(tmp2
, MKTEXT(11));
233 is_int(512, BUFSIZE
, MSG
);
234 is_string(tmp2
, substitution_parse("${text100}${text400}${text11}", &varlist2
), MSG
);
237 static void too_long_variable3a(void) {
240 strcpy(tmp2
, MKTEXT(100));
241 strcat(tmp2
, MKTEXT(400));
242 strcat(tmp2
, MKTEXT(12));
243 tmp2
[511] = 0; /* text will be truncated to 511 chars */
245 is_int(512, BUFSIZE
, MSG
);
246 is_string(tmp2
, substitution_parse("${text100}${text400}${text12}", &varlist2
), MSG
);
249 static void too_long_variable3b(void) {
252 strcpy(tmp2
, MKTEXT(100));
253 strcat(tmp2
, MKTEXT(400));
254 strcat(tmp2
, MKTEXT(13));
255 tmp2
[511] = 0; /* text will be truncated to 511 chars */
257 is_int(512, BUFSIZE
, MSG
);
258 is_string(tmp2
, substitution_parse("${text100}${text400}${text13}", &varlist2
), MSG
);
261 static void too_long_variable3c(void) {
264 strcpy(tmp2
, MKTEXT(200));
265 strcat(tmp2
, MKTEXT(400));
266 strcat(tmp2
, MKTEXT(100));
267 tmp2
[511] = 0; /* text will be truncated to 511 chars */
269 is_int(512, BUFSIZE
, MSG
);
270 is_string(tmp2
, substitution_parse("${text200}${text400}${text100}", &varlist2
), MSG
);
273 int main(int argc
, char *argv
[])
275 memset(&me
, 0, sizeof(me
));
276 strcpy(me
.name
, "me.name.");
278 rb_lib_init(NULL
, NULL
, NULL
, 0, 1024, DNODE_HEAP_SIZE
, FD_HEAP_SIZE
);
279 rb_linebuf_init(LINEBUF_HEAP_SIZE
);
281 substitution_append_var(&varlist
, "testB", "TESTB");
282 substitution_append_var(&varlist
, "test1", "TEST1");
283 substitution_append_var(&varlist
, "test2", "TEST2");
284 substitution_append_var(&varlist
, "test3", "TEST3");
285 substitution_append_var(&varlist
, "test4", "TEST4");
286 substitution_append_var(&varlist
, "test5", "TEST5");
287 substitution_append_var(&varlist
, "test9", "TEST9");
288 substitution_append_var(&varlist
, "testE", "TESTE");
290 substitution_append_var(&varlist2
, "text10", MKTEXT(10));
291 substitution_append_var(&varlist2
, "text11", MKTEXT(11));
292 substitution_append_var(&varlist2
, "text12", MKTEXT(12));
293 substitution_append_var(&varlist2
, "text13", MKTEXT(13));
294 substitution_append_var(&varlist2
, "text14", MKTEXT(14));
295 substitution_append_var(&varlist2
, "text100", MKTEXT(100));
296 substitution_append_var(&varlist2
, "text200", MKTEXT(200));
297 substitution_append_var(&varlist2
, "text400", MKTEXT(400));
298 substitution_append_var(&varlist2
, "text500", MKTEXT(500));
299 substitution_append_var(&varlist2
, "text510", MKTEXT(510));
300 substitution_append_var(&varlist2
, "text511", MKTEXT(511));
301 substitution_append_var(&varlist2
, "text512", MKTEXT(512));
302 substitution_append_var(&varlist2
, "text513", MKTEXT(513));
303 substitution_append_var(&varlist2
, "text514", MKTEXT(514));
304 substitution_append_var(&varlist2
, "text600", MKTEXT(600));
312 unterminated_variable1a();
313 unterminated_variable1b();
314 unterminated_variable2a();
315 unterminated_variable2b();
316 unterminated_missing_variable1();
317 unterminated_missing_variable2();
320 empty_unterminated_variable1();
321 empty_unterminated_variable2();
329 too_long_variable1a();
330 too_long_variable1b();
331 too_long_variable1c();
332 too_long_variable2a();
333 too_long_variable2b();
334 too_long_variable2c();
335 too_long_variable3a();
336 too_long_variable3b();
337 too_long_variable3c();