]> jfr.im git - solanum.git/blob - tests/rb_linebuf_put1.c
librb: add rb_snprintf_try_append
[solanum.git] / tests / rb_linebuf_put1.c
1 /*
2 * rb_linebuf_put1.c: Test rb_linebuf_put* under various conditions
3 * Copyright 2017 Simon Arlott
4 *
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.
9 *
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.
14 *
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
18 * USA
19 */
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "tap/basic.h"
25
26 #include "stdinc.h"
27 #include "ircd_defs.h"
28 #include "client.h"
29 #include "rb_lib.h"
30
31 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
32
33 struct Client me;
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"
46 ;
47 char long_tags[TAGSLEN + 1];
48 char long_prefix[TAGSLEN + DATALEN + 1];
49 char long_prefixf[TAGSLEN + DATALEN + 1];
50
51 #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
52
53 static void _rb_linebuf_put_vtags_prefix(buf_head_t *bufhead, size_t prefix_buflen, const char *prefix, const char *format, ...)
54 {
55 va_list args;
56
57 va_start(args, format);
58 rb_linebuf_put_vtags_prefix(bufhead, format, &args, prefix_buflen, prefix);
59 va_end(args);
60 }
61
62 static void _rb_linebuf_put_vtags_prefixf(buf_head_t *bufhead, size_t prefix_buflen, const char *prefix, const char *format, ...)
63 {
64 va_list args;
65
66 va_start(args, format);
67 rb_linebuf_put_vtags_prefixf(bufhead, format, &args, prefix_buflen, prefix, 300);
68 va_end(args);
69 }
70
71 static void _rb_linebuf_put_vmsg(buf_head_t *bufhead, const char *format, ...)
72 {
73 va_list args;
74
75 va_start(args, format);
76 rb_linebuf_put_vmsg(bufhead, format, &args);
77 va_end(args);
78 }
79
80 static void _rb_linebuf_put_vmsg_prefixf(buf_head_t *bufhead, const char *prefix, const char *format, ...)
81 {
82 va_list args;
83
84 va_start(args, format);
85 rb_linebuf_put_vmsg_prefixf(bufhead, format, &args, prefix, 300);
86 va_end(args);
87 }
88
89
90 #define CRLF "\r\n"
91 #define SOME_TAGS "@tag1=value1;tag2=value2 "
92
93 static void basic_vtags_prefix1(void)
94 {
95 buf_head_t linebuf;
96 char output[2048] = { 0 };
97 int len;
98
99 rb_linebuf_newbuf(&linebuf);
100 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":prefix ", "test %s %d", "TEST", 42);
101 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
102 rb_linebuf_donebuf(&linebuf);
103
104 is_int(strlen(output), len, MSG);
105 is_string(SOME_TAGS ":prefix test TEST 42" CRLF, output, MSG);
106 }
107
108 static void long_vtags_prefix1(void)
109 {
110 buf_head_t linebuf;
111 char output[2048] = { 0 };
112 int len;
113
114 rb_linebuf_newbuf(&linebuf);
115 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":prefix ", "%s", MKTEXT(502));
116 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
117 rb_linebuf_donebuf(&linebuf);
118
119 is_int(strlen(output), len, MSG);
120
121 char tmp[2048];
122
123 strcpy(tmp, SOME_TAGS ":prefix ");
124 strcat(tmp, MKTEXT(502));
125 strcat(tmp, CRLF);
126 is_string(tmp, output, MSG);
127 is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG);
128 }
129
130 static void too_long_vtags_prefix1(void)
131 {
132 buf_head_t linebuf;
133 char output[2048] = { 0 };
134 int len;
135
136 rb_linebuf_newbuf(&linebuf);
137 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":prefix ", "%s", MKTEXT(503));
138 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
139 rb_linebuf_donebuf(&linebuf);
140
141 is_int(strlen(output), len, MSG);
142
143 char tmp[2048];
144
145 strcpy(tmp, SOME_TAGS ":prefix ");
146 strcat(tmp, MKTEXT(503));
147 tmp[strlen(tmp) - 1] = 0; /* truncated message */
148 strcat(tmp, CRLF);
149 is_string(tmp, output, MSG);
150 is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG);
151 }
152
153 static void long_vtags_prefix2(void)
154 {
155 buf_head_t linebuf;
156 char output[2048] = { 0 };
157 char prefix[2048] = { 0 };
158 int len;
159
160 strcpy(prefix, long_tags);
161 strcat(prefix, ":prefix ");
162
163 rb_linebuf_newbuf(&linebuf);
164 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(long_tags) + DATALEN + 1, prefix, "%s", MKTEXT(502));
165 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
166 rb_linebuf_donebuf(&linebuf);
167
168 is_int(strlen(output), len, MSG);
169
170 char tmp[2048];
171
172 strcpy(tmp, long_tags);
173 strcat(tmp, ":prefix ");
174 strcat(tmp, MKTEXT(502));
175 strcat(tmp, CRLF);
176 is_string(tmp, output, MSG);
177 is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG);
178 }
179
180 static void too_long_vtags_prefix2(void)
181 {
182 buf_head_t linebuf;
183 char output[2048] = { 0 };
184 char prefix[2048] = { 0 };
185 int len;
186
187 strcpy(prefix, long_tags);
188 strcat(prefix, ":prefix ");
189
190 rb_linebuf_newbuf(&linebuf);
191 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(prefix) + DATALEN + 1, prefix, "%s", MKTEXT(503));
192 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
193 rb_linebuf_donebuf(&linebuf);
194
195 is_int(strlen(output), len, MSG);
196
197 char tmp[2048];
198
199 strcpy(tmp, long_tags);
200 strcat(tmp, ":prefix ");
201 strcat(tmp, MKTEXT(503));
202 tmp[strlen(tmp) - 1] = 0; /* truncated message */
203 strcat(tmp, CRLF);
204 is_string(tmp, output, MSG);
205 is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG);
206 }
207
208 static void long_vtags_prefix3(void)
209 {
210 buf_head_t linebuf;
211 char output[2048] = { 0 };
212 char prefix[2048] = { 0 };
213 int len;
214
215 strcpy(prefix, long_prefix);
216
217 rb_linebuf_newbuf(&linebuf);
218 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(long_prefix) + DATALEN + 1, prefix, "%s", MKTEXT(500));
219 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
220 rb_linebuf_donebuf(&linebuf);
221
222 is_int(strlen(output), len, MSG);
223
224 char tmp[2048];
225
226 strcpy(tmp, long_prefix);
227 strcat(tmp, CRLF);
228 is_string(tmp, output, MSG);
229 is_int(strlen(long_prefix) + strlen(CRLF), strlen(output), MSG);
230 }
231
232 static void too_long_vtags_prefix3(void)
233 {
234 buf_head_t linebuf;
235 char output[2048] = { 0 };
236 char prefix[2048] = { 0 };
237 int len;
238
239 strcpy(prefix, long_prefix);
240 strcat(prefix, ":");
241
242 rb_linebuf_newbuf(&linebuf);
243 _rb_linebuf_put_vtags_prefix(&linebuf, strlen(long_prefix) + DATALEN + 1, prefix, "%s", MKTEXT(500));
244 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
245 rb_linebuf_donebuf(&linebuf);
246
247 is_int(strlen(output), len, MSG);
248
249 char tmp[2048];
250
251 strcpy(tmp, long_prefix);
252 strcat(tmp, CRLF);
253 is_string(tmp, output, MSG);
254 is_int(strlen(long_prefix) + strlen(CRLF), strlen(output), MSG);
255 }
256
257 static void basic_vtags_prefixf1(void)
258 {
259 buf_head_t linebuf;
260 char output[2048] = { 0 };
261 int len;
262
263 rb_linebuf_newbuf(&linebuf);
264 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":pre%d ", "test %s %d", "TEST", 42);
265 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
266 rb_linebuf_donebuf(&linebuf);
267
268 is_int(strlen(output), len, MSG);
269 is_string(SOME_TAGS ":pre300 test TEST 42" CRLF, output, MSG);
270 }
271
272 static void long_vtags_prefixf1(void)
273 {
274 buf_head_t linebuf;
275 char output[2048] = { 0 };
276 int len;
277
278 rb_linebuf_newbuf(&linebuf);
279 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":pre%d ", "%s", MKTEXT(502));
280 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
281 rb_linebuf_donebuf(&linebuf);
282
283 is_int(strlen(output), len, MSG);
284
285 char tmp[2048];
286
287 strcpy(tmp, SOME_TAGS ":pre300 ");
288 strcat(tmp, MKTEXT(502));
289 strcat(tmp, CRLF);
290 is_string(tmp, output, MSG);
291 is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG);
292 }
293
294 static void too_long_vtags_prefixf1(void)
295 {
296 buf_head_t linebuf;
297 char output[2048] = { 0 };
298 int len;
299
300 rb_linebuf_newbuf(&linebuf);
301 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(SOME_TAGS) + DATALEN + 1, SOME_TAGS ":pre%d ", "%s", MKTEXT(503));
302 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
303 rb_linebuf_donebuf(&linebuf);
304
305 is_int(strlen(output), len, MSG);
306
307 char tmp[2048];
308
309 strcpy(tmp, SOME_TAGS ":pre300 ");
310 strcat(tmp, MKTEXT(503));
311 tmp[strlen(tmp) - 1] = 0; /* truncated message */
312 strcat(tmp, CRLF);
313 is_string(tmp, output, MSG);
314 is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG);
315 }
316
317 static void long_vtags_prefixf2(void)
318 {
319 buf_head_t linebuf;
320 char output[2048] = { 0 };
321 char prefix[2048] = { 0 };
322 int len;
323
324 strcpy(prefix, long_tags);
325 strcat(prefix, ":pre%d ");
326
327 rb_linebuf_newbuf(&linebuf);
328 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(long_tags) + DATALEN + 1, prefix, "%s", MKTEXT(502));
329 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
330 rb_linebuf_donebuf(&linebuf);
331
332 is_int(strlen(output), len, MSG);
333
334 char tmp[2048];
335
336 strcpy(tmp, long_tags);
337 strcat(tmp, ":pre300 ");
338 strcat(tmp, MKTEXT(502));
339 strcat(tmp, CRLF);
340 is_string(tmp, output, MSG);
341 is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG);
342 }
343
344 static void too_long_vtags_prefixf2(void)
345 {
346 buf_head_t linebuf;
347 char output[2048] = { 0 };
348 char prefix[2048] = { 0 };
349 int len;
350
351 strcpy(prefix, long_tags);
352 strcat(prefix, ":pre%d ");
353
354 rb_linebuf_newbuf(&linebuf);
355 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(long_tags) + DATALEN + 1, prefix, "%s", MKTEXT(503));
356 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
357 rb_linebuf_donebuf(&linebuf);
358
359 is_int(strlen(output), len, MSG);
360
361 char tmp[2048];
362
363 strcpy(tmp, long_tags);
364 strcat(tmp, ":pre300 ");
365 strcat(tmp, MKTEXT(503));
366 tmp[strlen(tmp) - 1] = 0; /* truncated message */
367 strcat(tmp, CRLF);
368 is_string(tmp, output, MSG);
369 is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG);
370 }
371
372 static void long_vtags_prefixf3(void)
373 {
374 buf_head_t linebuf;
375 char output[2048] = { 0 };
376 char prefix[2048] = { 0 };
377 int len;
378
379 strcpy(prefix, long_prefixf);
380
381 rb_linebuf_newbuf(&linebuf);
382 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(prefix) + 1 + DATALEN + 1, prefix, "%s", MKTEXT(500));
383 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
384 rb_linebuf_donebuf(&linebuf);
385
386 is_int(strlen(output), len, MSG);
387
388 char tmp[2048];
389
390 strcpy(tmp, long_prefixf);
391 tmp[strlen(tmp) - 2] = 0;
392 strcat(tmp, "300");
393 strcat(tmp, CRLF);
394 is_string(tmp, output, MSG);
395 is_int(strlen(long_prefixf) + 1 + strlen(CRLF), strlen(output), MSG);
396 }
397
398 static void too_long_vtags_prefixf3(void)
399 {
400 buf_head_t linebuf;
401 char output[2048] = { 0 };
402 char prefix[2048] = { 0 };
403 int len;
404
405 strcpy(prefix, long_prefixf);
406 strcat(prefix, ":");
407
408 rb_linebuf_newbuf(&linebuf);
409 _rb_linebuf_put_vtags_prefixf(&linebuf, strlen(prefix) + 1 + 1 + DATALEN + 1, prefix, "%s", MKTEXT(500));
410 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
411 rb_linebuf_donebuf(&linebuf);
412
413 is_int(strlen(output), len, MSG);
414
415 char tmp[2048];
416
417 strcpy(tmp, long_prefixf);
418 tmp[strlen(tmp) - 2] = 0;
419 strcat(tmp, "300");
420 strcat(tmp, CRLF);
421 is_string(tmp, output, MSG);
422 is_int(strlen(long_prefixf) + 1 + strlen(CRLF), strlen(output), MSG);
423 }
424
425 static void basic_msgf1(void)
426 {
427 buf_head_t linebuf;
428 char output[2048] = { 0 };
429 int len;
430
431 rb_linebuf_newbuf(&linebuf);
432 rb_linebuf_put_msgf(&linebuf, ":prefix test %s %d", "TEST", 42);
433 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
434 rb_linebuf_donebuf(&linebuf);
435
436 is_int(strlen(output), len, MSG);
437 is_string(":prefix test TEST 42" CRLF, output, MSG);
438 }
439
440 static void long_msgf1(void)
441 {
442 buf_head_t linebuf;
443 char output[2048] = { 0 };
444 int len;
445
446 rb_linebuf_newbuf(&linebuf);
447 rb_linebuf_put_msgf(&linebuf, ":prefix %s", MKTEXT(502));
448 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
449 rb_linebuf_donebuf(&linebuf);
450
451 is_int(strlen(output), len, MSG);
452
453 char tmp[2048];
454
455 strcpy(tmp, ":prefix ");
456 strcat(tmp, MKTEXT(502));
457 strcat(tmp, CRLF);
458 is_string(tmp, output, MSG);
459 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
460 }
461
462 static void too_long_msgf1(void)
463 {
464 buf_head_t linebuf;
465 char output[2048] = { 0 };
466 int len;
467
468 rb_linebuf_newbuf(&linebuf);
469 rb_linebuf_put_msgf(&linebuf, ":prefix %s", MKTEXT(503));
470 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
471 rb_linebuf_donebuf(&linebuf);
472
473 is_int(strlen(output), len, MSG);
474
475 char tmp[2048];
476
477 strcpy(tmp, ":prefix ");
478 strcat(tmp, MKTEXT(503));
479 tmp[strlen(tmp) - 1] = 0; /* truncated message */
480 strcat(tmp, CRLF);
481 is_string(tmp, output, MSG);
482 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
483 }
484
485 static void long_msgf2(void)
486 {
487 buf_head_t linebuf;
488 char output[2048] = { 0 };
489 char prefix[2048] = { 0 };
490 int len;
491
492 rb_linebuf_newbuf(&linebuf);
493 rb_linebuf_put_msgf(&linebuf, ":prefix %s", MKTEXT(502));
494 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
495 rb_linebuf_donebuf(&linebuf);
496
497 is_int(strlen(output), len, MSG);
498
499 char tmp[2048];
500
501 strcpy(tmp, ":prefix ");
502 strcat(tmp, MKTEXT(502));
503 strcat(tmp, CRLF);
504 is_string(tmp, output, MSG);
505 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
506 }
507
508 static void too_long_msgf2(void)
509 {
510 buf_head_t linebuf;
511 char output[2048] = { 0 };
512 char prefix[2048] = { 0 };
513 int len;
514
515 rb_linebuf_newbuf(&linebuf);
516 rb_linebuf_put_msgf(&linebuf, ":prefix %s", MKTEXT(503));
517 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
518 rb_linebuf_donebuf(&linebuf);
519
520 is_int(strlen(output), len, MSG);
521
522 char tmp[2048];
523
524 strcpy(tmp, ":prefix ");
525 strcat(tmp, MKTEXT(503));
526 tmp[strlen(tmp) - 1] = 0; /* truncated message */
527 strcat(tmp, CRLF);
528 is_string(tmp, output, MSG);
529 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
530 }
531
532 static void basic_vmsg1(void)
533 {
534 buf_head_t linebuf;
535 char output[2048] = { 0 };
536 int len;
537
538 rb_linebuf_newbuf(&linebuf);
539 _rb_linebuf_put_vmsg(&linebuf, ":prefix test %s %d", "TEST", 42);
540 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
541 rb_linebuf_donebuf(&linebuf);
542
543 is_int(strlen(output), len, MSG);
544 is_string(":prefix test TEST 42" CRLF, output, MSG);
545 }
546
547 static void long_vmsg1(void)
548 {
549 buf_head_t linebuf;
550 char output[2048] = { 0 };
551 int len;
552
553 rb_linebuf_newbuf(&linebuf);
554 _rb_linebuf_put_vmsg(&linebuf, ":prefix %s", MKTEXT(502));
555 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
556 rb_linebuf_donebuf(&linebuf);
557
558 is_int(strlen(output), len, MSG);
559
560 char tmp[2048];
561
562 strcpy(tmp, ":prefix ");
563 strcat(tmp, MKTEXT(502));
564 strcat(tmp, CRLF);
565 is_string(tmp, output, MSG);
566 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
567 }
568
569 static void too_long_vmsg1(void)
570 {
571 buf_head_t linebuf;
572 char output[2048] = { 0 };
573 int len;
574
575 rb_linebuf_newbuf(&linebuf);
576 _rb_linebuf_put_vmsg(&linebuf, ":prefix %s", MKTEXT(503));
577 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
578 rb_linebuf_donebuf(&linebuf);
579
580 is_int(strlen(output), len, MSG);
581
582 char tmp[2048];
583
584 strcpy(tmp, ":prefix ");
585 strcat(tmp, MKTEXT(503));
586 tmp[strlen(tmp) - 1] = 0; /* truncated message */
587 strcat(tmp, CRLF);
588 is_string(tmp, output, MSG);
589 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
590 }
591
592 static void long_vmsg2(void)
593 {
594 buf_head_t linebuf;
595 char output[2048] = { 0 };
596 char prefix[2048] = { 0 };
597 int len;
598
599 rb_linebuf_newbuf(&linebuf);
600 _rb_linebuf_put_vmsg(&linebuf, ":prefix %s", MKTEXT(502));
601 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
602 rb_linebuf_donebuf(&linebuf);
603
604 is_int(strlen(output), len, MSG);
605
606 char tmp[2048];
607
608 strcpy(tmp, ":prefix ");
609 strcat(tmp, MKTEXT(502));
610 strcat(tmp, CRLF);
611 is_string(tmp, output, MSG);
612 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
613 }
614
615 static void too_long_vmsg2(void)
616 {
617 buf_head_t linebuf;
618 char output[2048] = { 0 };
619 char prefix[2048] = { 0 };
620 int len;
621
622 rb_linebuf_newbuf(&linebuf);
623 _rb_linebuf_put_vmsg(&linebuf, ":prefix %s", MKTEXT(503));
624 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
625 rb_linebuf_donebuf(&linebuf);
626
627 is_int(strlen(output), len, MSG);
628
629 char tmp[2048];
630
631 strcpy(tmp, ":prefix ");
632 strcat(tmp, MKTEXT(503));
633 tmp[strlen(tmp) - 1] = 0; /* truncated message */
634 strcat(tmp, CRLF);
635 is_string(tmp, output, MSG);
636 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
637 }
638
639 static void basic_vmsg_prefixf1(void)
640 {
641 buf_head_t linebuf;
642 char output[2048] = { 0 };
643 int len;
644
645 rb_linebuf_newbuf(&linebuf);
646 _rb_linebuf_put_vmsg_prefixf(&linebuf, ":pre%d ", "test %s %d", "TEST", 42);
647 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
648 rb_linebuf_donebuf(&linebuf);
649
650 is_int(strlen(output), len, MSG);
651 is_string(":pre300 test TEST 42" CRLF, output, MSG);
652 }
653
654 static void long_vmsg_prefixf1(void)
655 {
656 buf_head_t linebuf;
657 char output[2048] = { 0 };
658 int len;
659
660 rb_linebuf_newbuf(&linebuf);
661 _rb_linebuf_put_vmsg_prefixf(&linebuf, ":pre%d ", "%s", MKTEXT(502));
662 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
663 rb_linebuf_donebuf(&linebuf);
664
665 is_int(strlen(output), len, MSG);
666
667 char tmp[2048];
668
669 strcpy(tmp, ":pre300 ");
670 strcat(tmp, MKTEXT(502));
671 strcat(tmp, CRLF);
672 is_string(tmp, output, MSG);
673 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
674 }
675
676 static void too_long_vmsg_prefixf1(void)
677 {
678 buf_head_t linebuf;
679 char output[2048] = { 0 };
680 int len;
681
682 rb_linebuf_newbuf(&linebuf);
683 _rb_linebuf_put_vmsg_prefixf(&linebuf, ":pre%d ", "%s", MKTEXT(503));
684 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
685 rb_linebuf_donebuf(&linebuf);
686
687 is_int(strlen(output), len, MSG);
688
689 char tmp[2048];
690
691 strcpy(tmp, ":pre300 ");
692 strcat(tmp, MKTEXT(503));
693 tmp[strlen(tmp) - 1] = 0; /* truncated message */
694 strcat(tmp, CRLF);
695 is_string(tmp, output, MSG);
696 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
697 }
698
699 static void long_vmsg_prefixf2(void)
700 {
701 buf_head_t linebuf;
702 char output[2048] = { 0 };
703 int len;
704
705 rb_linebuf_newbuf(&linebuf);
706 _rb_linebuf_put_vmsg_prefixf(&linebuf, ":pre%d ", "%s", MKTEXT(502));
707 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
708 rb_linebuf_donebuf(&linebuf);
709
710 is_int(strlen(output), len, MSG);
711
712 char tmp[2048];
713
714 strcpy(tmp, ":pre300 ");
715 strcat(tmp, MKTEXT(502));
716 strcat(tmp, CRLF);
717 is_string(tmp, output, MSG);
718 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
719 }
720
721 static void too_long_vmsg_prefixf2(void)
722 {
723 buf_head_t linebuf;
724 char output[2048] = { 0 };
725 int len;
726
727 rb_linebuf_newbuf(&linebuf);
728 _rb_linebuf_put_vmsg_prefixf(&linebuf, ":pre%d ", "%s", MKTEXT(503));
729 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
730 rb_linebuf_donebuf(&linebuf);
731
732 is_int(strlen(output), len, MSG);
733
734 char tmp[2048];
735
736 strcpy(tmp, ":pre300 ");
737 strcat(tmp, MKTEXT(503));
738 tmp[strlen(tmp) - 1] = 0; /* truncated message */
739 strcat(tmp, CRLF);
740 is_string(tmp, output, MSG);
741 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
742 }
743
744 static void long_vmsg_prefixf3(void)
745 {
746 buf_head_t linebuf;
747 char output[2048] = { 0 };
748 char prefix[2048] = { 0 };
749 int len;
750
751 strcpy(prefix, MKTEXT(507));
752 strcat(prefix, "%d");
753
754 rb_linebuf_newbuf(&linebuf);
755 _rb_linebuf_put_vmsg_prefixf(&linebuf, prefix, "%s", MKTEXT(500));
756 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
757 rb_linebuf_donebuf(&linebuf);
758
759 is_int(strlen(output), len, MSG);
760
761 char tmp[2048];
762
763 strcpy(tmp, MKTEXT(507));
764 strcat(tmp, "300");
765 strcat(tmp, CRLF);
766 is_string(tmp, output, MSG);
767 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
768 }
769
770 static void too_long_vmsg_prefixf3(void)
771 {
772 buf_head_t linebuf;
773 char output[2048] = { 0 };
774 char prefix[2048] = { 0 };
775 int len;
776
777 strcpy(prefix, MKTEXT(508));
778 strcat(prefix, "%d");
779
780 rb_linebuf_newbuf(&linebuf);
781 _rb_linebuf_put_vmsg_prefixf(&linebuf, prefix, "%s", MKTEXT(500));
782 len = rb_linebuf_get(&linebuf, output, sizeof(output), 0, 1);
783 rb_linebuf_donebuf(&linebuf);
784
785 is_int(strlen(output), len, MSG);
786
787 char tmp[2048];
788
789 strcpy(tmp, MKTEXT(508));
790 strcat(tmp, "300");
791 tmp[strlen(tmp) - 1] = 0; /* truncated message */
792 strcat(tmp, CRLF);
793 is_string(tmp, output, MSG);
794 is_int(DATALEN + strlen(CRLF), strlen(output), MSG);
795 }
796
797 int main(int argc, char *argv[])
798 {
799 memset(&me, 0, sizeof(me));
800 strcpy(me.name, "me.name.");
801
802 strcpy(long_tags, "@");
803 strcat(long_tags, MKTEXT(510));
804 strcat(long_tags, " ");
805
806 /* no space for any additional message */
807 strcpy(long_prefix, "@");
808 strcat(long_prefix, MKTEXT(510));
809 strcat(long_prefix, " ");
810 strcat(long_prefix, MKTEXT(510));
811
812 strcpy(long_prefixf, "@");
813 strcat(long_prefixf, MKTEXT(510));
814 strcat(long_prefixf, " ");
815 strcat(long_prefixf, MKTEXT(507));
816 strcat(long_prefixf, "%d");
817
818 rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
819 rb_linebuf_init(LINEBUF_HEAP_SIZE);
820
821 plan_lazy();
822
823 is_int(512, TAGSLEN, MSG);
824 is_int(510, DATALEN, MSG);
825
826 is_int(TAGSLEN, strlen(long_tags), MSG);
827 is_int(TAGSLEN + DATALEN, strlen(long_prefix), MSG);
828 /* this is a format string, "%d" -> "300", so 1 char short */
829 is_int(TAGSLEN + DATALEN - 1, strlen(long_prefixf), MSG);
830
831 basic_vtags_prefix1();
832 long_vtags_prefix1();
833 too_long_vtags_prefix1();
834 long_vtags_prefix2();
835 too_long_vtags_prefix2();
836 long_vtags_prefix3();
837 too_long_vtags_prefix3();
838
839 basic_vtags_prefixf1();
840 long_vtags_prefixf1();
841 too_long_vtags_prefixf1();
842 long_vtags_prefixf2();
843 too_long_vtags_prefixf2();
844 long_vtags_prefixf3();
845 too_long_vtags_prefixf3();
846
847 basic_msgf1();
848 long_msgf1();
849 too_long_msgf1();
850 long_msgf2();
851 too_long_msgf2();
852
853 basic_vmsg1();
854 long_vmsg1();
855 too_long_vmsg1();
856 long_vmsg2();
857 too_long_vmsg2();
858
859 basic_vmsg_prefixf1();
860 long_vmsg_prefixf1();
861 too_long_vmsg_prefixf1();
862 long_vmsg_prefixf2();
863 too_long_vmsg_prefixf2();
864 long_vmsg_prefixf3();
865 too_long_vmsg_prefixf3();
866
867 return 0;
868 }