]>
jfr.im git - solanum.git/blob - tests/rb_linebuf_put1.c
2 * rb_linebuf_put1.c: Test rb_linebuf_put* 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"
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"
47 char long_tags
[TAGSLEN
+ 1];
48 char long_prefix
[TAGSLEN
+ DATALEN
+ 1];
49 char long_prefixf
[TAGSLEN
+ DATALEN
+ 1];
51 #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
53 static void _rb_linebuf_put_vtags_prefix(buf_head_t
*bufhead
, size_t prefix_buflen
, const char *prefix
, const char *format
, ...)
57 va_start(args
, format
);
58 rb_linebuf_put_vtags_prefix(bufhead
, format
, &args
, prefix_buflen
, prefix
);
62 static void _rb_linebuf_put_vtags_prefixf(buf_head_t
*bufhead
, size_t prefix_buflen
, const char *prefix
, const char *format
, ...)
66 va_start(args
, format
);
67 rb_linebuf_put_vtags_prefixf(bufhead
, format
, &args
, prefix_buflen
, prefix
, 300);
71 static void _rb_linebuf_put_vmsg(buf_head_t
*bufhead
, const char *format
, ...)
75 va_start(args
, format
);
76 rb_linebuf_put_vmsg(bufhead
, format
, &args
);
80 static void _rb_linebuf_put_vmsg_prefixf(buf_head_t
*bufhead
, const char *prefix
, const char *format
, ...)
84 va_start(args
, format
);
85 rb_linebuf_put_vmsg_prefixf(bufhead
, format
, &args
, prefix
, 300);
91 #define SOME_TAGS "@tag1=value1;tag2=value2 "
93 static void basic_vtags_prefix1(void)
96 char output
[2048] = { 0 };
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
);
104 is_int(strlen(output
), len
, MSG
);
105 is_string(SOME_TAGS
":prefix test TEST 42" CRLF
, output
, MSG
);
108 static void long_vtags_prefix1(void)
111 char output
[2048] = { 0 };
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
);
119 is_int(strlen(output
), len
, MSG
);
123 strcpy(tmp
, SOME_TAGS
":prefix ");
124 strcat(tmp
, MKTEXT(502));
126 is_string(tmp
, output
, MSG
);
127 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
130 static void too_long_vtags_prefix1(void)
133 char output
[2048] = { 0 };
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
);
141 is_int(strlen(output
), len
, MSG
);
145 strcpy(tmp
, SOME_TAGS
":prefix ");
146 strcat(tmp
, MKTEXT(503));
147 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
149 is_string(tmp
, output
, MSG
);
150 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
153 static void long_vtags_prefix2(void)
156 char output
[2048] = { 0 };
157 char prefix
[2048] = { 0 };
160 strcpy(prefix
, long_tags
);
161 strcat(prefix
, ":prefix ");
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
);
168 is_int(strlen(output
), len
, MSG
);
172 strcpy(tmp
, long_tags
);
173 strcat(tmp
, ":prefix ");
174 strcat(tmp
, MKTEXT(502));
176 is_string(tmp
, output
, MSG
);
177 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
180 static void too_long_vtags_prefix2(void)
183 char output
[2048] = { 0 };
184 char prefix
[2048] = { 0 };
187 strcpy(prefix
, long_tags
);
188 strcat(prefix
, ":prefix ");
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
);
195 is_int(strlen(output
), len
, MSG
);
199 strcpy(tmp
, long_tags
);
200 strcat(tmp
, ":prefix ");
201 strcat(tmp
, MKTEXT(503));
202 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
204 is_string(tmp
, output
, MSG
);
205 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
208 static void long_vtags_prefix3(void)
211 char output
[2048] = { 0 };
212 char prefix
[2048] = { 0 };
215 strcpy(prefix
, long_prefix
);
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
);
222 is_int(strlen(output
), len
, MSG
);
226 strcpy(tmp
, long_prefix
);
228 is_string(tmp
, output
, MSG
);
229 is_int(strlen(long_prefix
) + strlen(CRLF
), strlen(output
), MSG
);
232 static void too_long_vtags_prefix3(void)
235 char output
[2048] = { 0 };
236 char prefix
[2048] = { 0 };
239 strcpy(prefix
, long_prefix
);
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
);
247 is_int(strlen(output
), len
, MSG
);
251 strcpy(tmp
, long_prefix
);
253 is_string(tmp
, output
, MSG
);
254 is_int(strlen(long_prefix
) + strlen(CRLF
), strlen(output
), MSG
);
257 static void basic_vtags_prefixf1(void)
260 char output
[2048] = { 0 };
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
);
268 is_int(strlen(output
), len
, MSG
);
269 is_string(SOME_TAGS
":pre300 test TEST 42" CRLF
, output
, MSG
);
272 static void long_vtags_prefixf1(void)
275 char output
[2048] = { 0 };
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
);
283 is_int(strlen(output
), len
, MSG
);
287 strcpy(tmp
, SOME_TAGS
":pre300 ");
288 strcat(tmp
, MKTEXT(502));
290 is_string(tmp
, output
, MSG
);
291 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
294 static void too_long_vtags_prefixf1(void)
297 char output
[2048] = { 0 };
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
);
305 is_int(strlen(output
), len
, MSG
);
309 strcpy(tmp
, SOME_TAGS
":pre300 ");
310 strcat(tmp
, MKTEXT(503));
311 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
313 is_string(tmp
, output
, MSG
);
314 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
317 static void long_vtags_prefixf2(void)
320 char output
[2048] = { 0 };
321 char prefix
[2048] = { 0 };
324 strcpy(prefix
, long_tags
);
325 strcat(prefix
, ":pre%d ");
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
);
332 is_int(strlen(output
), len
, MSG
);
336 strcpy(tmp
, long_tags
);
337 strcat(tmp
, ":pre300 ");
338 strcat(tmp
, MKTEXT(502));
340 is_string(tmp
, output
, MSG
);
341 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
344 static void too_long_vtags_prefixf2(void)
347 char output
[2048] = { 0 };
348 char prefix
[2048] = { 0 };
351 strcpy(prefix
, long_tags
);
352 strcat(prefix
, ":pre%d ");
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
);
359 is_int(strlen(output
), len
, MSG
);
363 strcpy(tmp
, long_tags
);
364 strcat(tmp
, ":pre300 ");
365 strcat(tmp
, MKTEXT(503));
366 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
368 is_string(tmp
, output
, MSG
);
369 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
372 static void long_vtags_prefixf3(void)
375 char output
[2048] = { 0 };
376 char prefix
[2048] = { 0 };
379 strcpy(prefix
, long_prefixf
);
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
);
386 is_int(strlen(output
), len
, MSG
);
390 strcpy(tmp
, long_prefixf
);
391 tmp
[strlen(tmp
) - 2] = 0;
394 is_string(tmp
, output
, MSG
);
395 is_int(strlen(long_prefixf
) + 1 + strlen(CRLF
), strlen(output
), MSG
);
398 static void too_long_vtags_prefixf3(void)
401 char output
[2048] = { 0 };
402 char prefix
[2048] = { 0 };
405 strcpy(prefix
, long_prefixf
);
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
);
413 is_int(strlen(output
), len
, MSG
);
417 strcpy(tmp
, long_prefixf
);
418 tmp
[strlen(tmp
) - 2] = 0;
421 is_string(tmp
, output
, MSG
);
422 is_int(strlen(long_prefixf
) + 1 + strlen(CRLF
), strlen(output
), MSG
);
425 static void basic_msgf1(void)
428 char output
[2048] = { 0 };
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
);
436 is_int(strlen(output
), len
, MSG
);
437 is_string(":prefix test TEST 42" CRLF
, output
, MSG
);
440 static void long_msgf1(void)
443 char output
[2048] = { 0 };
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
);
451 is_int(strlen(output
), len
, MSG
);
455 strcpy(tmp
, ":prefix ");
456 strcat(tmp
, MKTEXT(502));
458 is_string(tmp
, output
, MSG
);
459 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
462 static void too_long_msgf1(void)
465 char output
[2048] = { 0 };
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
);
473 is_int(strlen(output
), len
, MSG
);
477 strcpy(tmp
, ":prefix ");
478 strcat(tmp
, MKTEXT(503));
479 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
481 is_string(tmp
, output
, MSG
);
482 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
485 static void long_msgf2(void)
488 char output
[2048] = { 0 };
489 char prefix
[2048] = { 0 };
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
);
497 is_int(strlen(output
), len
, MSG
);
501 strcpy(tmp
, ":prefix ");
502 strcat(tmp
, MKTEXT(502));
504 is_string(tmp
, output
, MSG
);
505 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
508 static void too_long_msgf2(void)
511 char output
[2048] = { 0 };
512 char prefix
[2048] = { 0 };
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
);
520 is_int(strlen(output
), len
, MSG
);
524 strcpy(tmp
, ":prefix ");
525 strcat(tmp
, MKTEXT(503));
526 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
528 is_string(tmp
, output
, MSG
);
529 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
532 static void basic_vmsg1(void)
535 char output
[2048] = { 0 };
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
);
543 is_int(strlen(output
), len
, MSG
);
544 is_string(":prefix test TEST 42" CRLF
, output
, MSG
);
547 static void long_vmsg1(void)
550 char output
[2048] = { 0 };
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
);
558 is_int(strlen(output
), len
, MSG
);
562 strcpy(tmp
, ":prefix ");
563 strcat(tmp
, MKTEXT(502));
565 is_string(tmp
, output
, MSG
);
566 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
569 static void too_long_vmsg1(void)
572 char output
[2048] = { 0 };
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
);
580 is_int(strlen(output
), len
, MSG
);
584 strcpy(tmp
, ":prefix ");
585 strcat(tmp
, MKTEXT(503));
586 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
588 is_string(tmp
, output
, MSG
);
589 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
592 static void long_vmsg2(void)
595 char output
[2048] = { 0 };
596 char prefix
[2048] = { 0 };
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
);
604 is_int(strlen(output
), len
, MSG
);
608 strcpy(tmp
, ":prefix ");
609 strcat(tmp
, MKTEXT(502));
611 is_string(tmp
, output
, MSG
);
612 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
615 static void too_long_vmsg2(void)
618 char output
[2048] = { 0 };
619 char prefix
[2048] = { 0 };
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
);
627 is_int(strlen(output
), len
, MSG
);
631 strcpy(tmp
, ":prefix ");
632 strcat(tmp
, MKTEXT(503));
633 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
635 is_string(tmp
, output
, MSG
);
636 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
639 static void basic_vmsg_prefixf1(void)
642 char output
[2048] = { 0 };
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
);
650 is_int(strlen(output
), len
, MSG
);
651 is_string(":pre300 test TEST 42" CRLF
, output
, MSG
);
654 static void long_vmsg_prefixf1(void)
657 char output
[2048] = { 0 };
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
);
665 is_int(strlen(output
), len
, MSG
);
669 strcpy(tmp
, ":pre300 ");
670 strcat(tmp
, MKTEXT(502));
672 is_string(tmp
, output
, MSG
);
673 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
676 static void too_long_vmsg_prefixf1(void)
679 char output
[2048] = { 0 };
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
);
687 is_int(strlen(output
), len
, MSG
);
691 strcpy(tmp
, ":pre300 ");
692 strcat(tmp
, MKTEXT(503));
693 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
695 is_string(tmp
, output
, MSG
);
696 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
699 static void long_vmsg_prefixf2(void)
702 char output
[2048] = { 0 };
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
);
710 is_int(strlen(output
), len
, MSG
);
714 strcpy(tmp
, ":pre300 ");
715 strcat(tmp
, MKTEXT(502));
717 is_string(tmp
, output
, MSG
);
718 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
721 static void too_long_vmsg_prefixf2(void)
724 char output
[2048] = { 0 };
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
);
732 is_int(strlen(output
), len
, MSG
);
736 strcpy(tmp
, ":pre300 ");
737 strcat(tmp
, MKTEXT(503));
738 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
740 is_string(tmp
, output
, MSG
);
741 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
744 static void long_vmsg_prefixf3(void)
747 char output
[2048] = { 0 };
748 char prefix
[2048] = { 0 };
751 strcpy(prefix
, MKTEXT(507));
752 strcat(prefix
, "%d");
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
);
759 is_int(strlen(output
), len
, MSG
);
763 strcpy(tmp
, MKTEXT(507));
766 is_string(tmp
, output
, MSG
);
767 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
770 static void too_long_vmsg_prefixf3(void)
773 char output
[2048] = { 0 };
774 char prefix
[2048] = { 0 };
777 strcpy(prefix
, MKTEXT(508));
778 strcat(prefix
, "%d");
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
);
785 is_int(strlen(output
), len
, MSG
);
789 strcpy(tmp
, MKTEXT(508));
791 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
793 is_string(tmp
, output
, MSG
);
794 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
797 int main(int argc
, char *argv
[])
799 memset(&me
, 0, sizeof(me
));
800 strcpy(me
.name
, "me.name.");
802 strcpy(long_tags
, "@");
803 strcat(long_tags
, MKTEXT(510));
804 strcat(long_tags
, " ");
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));
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");
818 rb_lib_init(NULL
, NULL
, NULL
, 0, 1024, DNODE_HEAP_SIZE
, FD_HEAP_SIZE
);
819 rb_linebuf_init(LINEBUF_HEAP_SIZE
);
823 is_int(512, TAGSLEN
, MSG
);
824 is_int(510, DATALEN
, MSG
);
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
);
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();
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();
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();