]>
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 const char text
[] =
35 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
36 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
37 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
38 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
39 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
40 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
41 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
42 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
43 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
44 "ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
46 char long_tags
[TAGSLEN
+ 1];
47 char long_prefix
[TAGSLEN
+ DATALEN
+ 1];
48 char long_prefixf
[TAGSLEN
+ DATALEN
+ 1];
50 #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)]
52 static void _rb_linebuf_put_vtags_prefix(buf_head_t
*bufhead
, size_t prefix_buflen
, const char *prefix
, const char *format
, ...)
56 va_start(args
, format
);
57 rb_linebuf_put_vtags_prefix(bufhead
, format
, &args
, prefix_buflen
, prefix
);
61 static void _rb_linebuf_put_vtags_prefixf(buf_head_t
*bufhead
, size_t prefix_buflen
, const char *prefix
, const char *format
, ...)
65 va_start(args
, format
);
66 rb_linebuf_put_vtags_prefixf(bufhead
, format
, &args
, prefix_buflen
, prefix
, 300);
70 static void _rb_linebuf_put_vmsg(buf_head_t
*bufhead
, const char *format
, ...)
74 va_start(args
, format
);
75 rb_linebuf_put_vmsg(bufhead
, format
, &args
);
79 static void _rb_linebuf_put_vmsg_prefixf(buf_head_t
*bufhead
, const char *prefix
, const char *format
, ...)
83 va_start(args
, format
);
84 rb_linebuf_put_vmsg_prefixf(bufhead
, format
, &args
, prefix
, 300);
90 #define SOME_TAGS "@tag1=value1;tag2=value2 "
92 static void basic_vtags_prefix1(void)
95 char output
[2048] = { 0 };
98 rb_linebuf_newbuf(&linebuf
);
99 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":prefix ", "test %s %d", "TEST", 42);
100 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
101 rb_linebuf_donebuf(&linebuf
);
103 is_int(strlen(output
), len
, MSG
);
104 is_string(SOME_TAGS
":prefix test TEST 42" CRLF
, output
, MSG
);
107 static void long_vtags_prefix1(void)
110 char output
[2048] = { 0 };
113 rb_linebuf_newbuf(&linebuf
);
114 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":prefix ", "%s", MKTEXT(502));
115 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
116 rb_linebuf_donebuf(&linebuf
);
118 is_int(strlen(output
), len
, MSG
);
122 strcpy(tmp
, SOME_TAGS
":prefix ");
123 strcat(tmp
, MKTEXT(502));
125 is_string(tmp
, output
, MSG
);
126 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
129 static void too_long_vtags_prefix1(void)
132 char output
[2048] = { 0 };
135 rb_linebuf_newbuf(&linebuf
);
136 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":prefix ", "%s", MKTEXT(503));
137 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
138 rb_linebuf_donebuf(&linebuf
);
140 is_int(strlen(output
), len
, MSG
);
144 strcpy(tmp
, SOME_TAGS
":prefix ");
145 strcat(tmp
, MKTEXT(503));
146 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
148 is_string(tmp
, output
, MSG
);
149 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
152 static void long_vtags_prefix2(void)
155 char output
[2048] = { 0 };
156 char prefix
[2048] = { 0 };
159 strcpy(prefix
, long_tags
);
160 strcat(prefix
, ":prefix ");
162 rb_linebuf_newbuf(&linebuf
);
163 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(long_tags
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(502));
164 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
165 rb_linebuf_donebuf(&linebuf
);
167 is_int(strlen(output
), len
, MSG
);
171 strcpy(tmp
, long_tags
);
172 strcat(tmp
, ":prefix ");
173 strcat(tmp
, MKTEXT(502));
175 is_string(tmp
, output
, MSG
);
176 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
179 static void too_long_vtags_prefix2(void)
182 char output
[2048] = { 0 };
183 char prefix
[2048] = { 0 };
186 strcpy(prefix
, long_tags
);
187 strcat(prefix
, ":prefix ");
189 rb_linebuf_newbuf(&linebuf
);
190 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(prefix
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(503));
191 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
192 rb_linebuf_donebuf(&linebuf
);
194 is_int(strlen(output
), len
, MSG
);
198 strcpy(tmp
, long_tags
);
199 strcat(tmp
, ":prefix ");
200 strcat(tmp
, MKTEXT(503));
201 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
203 is_string(tmp
, output
, MSG
);
204 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
207 static void long_vtags_prefix3(void)
210 char output
[2048] = { 0 };
211 char prefix
[2048] = { 0 };
214 strcpy(prefix
, long_prefix
);
216 rb_linebuf_newbuf(&linebuf
);
217 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(long_prefix
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(500));
218 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
219 rb_linebuf_donebuf(&linebuf
);
221 is_int(strlen(output
), len
, MSG
);
225 strcpy(tmp
, long_prefix
);
227 is_string(tmp
, output
, MSG
);
228 is_int(strlen(long_prefix
) + strlen(CRLF
), strlen(output
), MSG
);
231 static void too_long_vtags_prefix3(void)
234 char output
[2048] = { 0 };
235 char prefix
[2048] = { 0 };
238 strcpy(prefix
, long_prefix
);
241 rb_linebuf_newbuf(&linebuf
);
242 _rb_linebuf_put_vtags_prefix(&linebuf
, strlen(long_prefix
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(500));
243 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
244 rb_linebuf_donebuf(&linebuf
);
246 is_int(strlen(output
), len
, MSG
);
250 strcpy(tmp
, long_prefix
);
252 is_string(tmp
, output
, MSG
);
253 is_int(strlen(long_prefix
) + strlen(CRLF
), strlen(output
), MSG
);
256 static void basic_vtags_prefixf1(void)
259 char output
[2048] = { 0 };
262 rb_linebuf_newbuf(&linebuf
);
263 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":pre%d ", "test %s %d", "TEST", 42);
264 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
265 rb_linebuf_donebuf(&linebuf
);
267 is_int(strlen(output
), len
, MSG
);
268 is_string(SOME_TAGS
":pre300 test TEST 42" CRLF
, output
, MSG
);
271 static void long_vtags_prefixf1(void)
274 char output
[2048] = { 0 };
277 rb_linebuf_newbuf(&linebuf
);
278 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":pre%d ", "%s", MKTEXT(502));
279 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
280 rb_linebuf_donebuf(&linebuf
);
282 is_int(strlen(output
), len
, MSG
);
286 strcpy(tmp
, SOME_TAGS
":pre300 ");
287 strcat(tmp
, MKTEXT(502));
289 is_string(tmp
, output
, MSG
);
290 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
293 static void too_long_vtags_prefixf1(void)
296 char output
[2048] = { 0 };
299 rb_linebuf_newbuf(&linebuf
);
300 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(SOME_TAGS
) + DATALEN
+ 1, SOME_TAGS
":pre%d ", "%s", MKTEXT(503));
301 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
302 rb_linebuf_donebuf(&linebuf
);
304 is_int(strlen(output
), len
, MSG
);
308 strcpy(tmp
, SOME_TAGS
":pre300 ");
309 strcat(tmp
, MKTEXT(503));
310 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
312 is_string(tmp
, output
, MSG
);
313 is_int(strlen(SOME_TAGS
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
316 static void long_vtags_prefixf2(void)
319 char output
[2048] = { 0 };
320 char prefix
[2048] = { 0 };
323 strcpy(prefix
, long_tags
);
324 strcat(prefix
, ":pre%d ");
326 rb_linebuf_newbuf(&linebuf
);
327 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(long_tags
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(502));
328 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
329 rb_linebuf_donebuf(&linebuf
);
331 is_int(strlen(output
), len
, MSG
);
335 strcpy(tmp
, long_tags
);
336 strcat(tmp
, ":pre300 ");
337 strcat(tmp
, MKTEXT(502));
339 is_string(tmp
, output
, MSG
);
340 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
343 static void too_long_vtags_prefixf2(void)
346 char output
[2048] = { 0 };
347 char prefix
[2048] = { 0 };
350 strcpy(prefix
, long_tags
);
351 strcat(prefix
, ":pre%d ");
353 rb_linebuf_newbuf(&linebuf
);
354 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(long_tags
) + DATALEN
+ 1, prefix
, "%s", MKTEXT(503));
355 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
356 rb_linebuf_donebuf(&linebuf
);
358 is_int(strlen(output
), len
, MSG
);
362 strcpy(tmp
, long_tags
);
363 strcat(tmp
, ":pre300 ");
364 strcat(tmp
, MKTEXT(503));
365 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
367 is_string(tmp
, output
, MSG
);
368 is_int(strlen(long_tags
) + DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
371 static void long_vtags_prefixf3(void)
374 char output
[2048] = { 0 };
375 char prefix
[2048] = { 0 };
378 strcpy(prefix
, long_prefixf
);
380 rb_linebuf_newbuf(&linebuf
);
381 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(prefix
) + 1 + DATALEN
+ 1, prefix
, "%s", MKTEXT(500));
382 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
383 rb_linebuf_donebuf(&linebuf
);
385 is_int(strlen(output
), len
, MSG
);
389 strcpy(tmp
, long_prefixf
);
390 tmp
[strlen(tmp
) - 2] = 0;
393 is_string(tmp
, output
, MSG
);
394 is_int(strlen(long_prefixf
) + 1 + strlen(CRLF
), strlen(output
), MSG
);
397 static void too_long_vtags_prefixf3(void)
400 char output
[2048] = { 0 };
401 char prefix
[2048] = { 0 };
404 strcpy(prefix
, long_prefixf
);
407 rb_linebuf_newbuf(&linebuf
);
408 _rb_linebuf_put_vtags_prefixf(&linebuf
, strlen(prefix
) + 1 + 1 + DATALEN
+ 1, prefix
, "%s", MKTEXT(500));
409 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
410 rb_linebuf_donebuf(&linebuf
);
412 is_int(strlen(output
), len
, MSG
);
416 strcpy(tmp
, long_prefixf
);
417 tmp
[strlen(tmp
) - 2] = 0;
420 is_string(tmp
, output
, MSG
);
421 is_int(strlen(long_prefixf
) + 1 + strlen(CRLF
), strlen(output
), MSG
);
424 static void basic_msgf1(void)
427 char output
[2048] = { 0 };
430 rb_linebuf_newbuf(&linebuf
);
431 rb_linebuf_put_msgf(&linebuf
, ":prefix test %s %d", "TEST", 42);
432 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
433 rb_linebuf_donebuf(&linebuf
);
435 is_int(strlen(output
), len
, MSG
);
436 is_string(":prefix test TEST 42" CRLF
, output
, MSG
);
439 static void long_msgf1(void)
442 char output
[2048] = { 0 };
445 rb_linebuf_newbuf(&linebuf
);
446 rb_linebuf_put_msgf(&linebuf
, ":prefix %s", MKTEXT(502));
447 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
448 rb_linebuf_donebuf(&linebuf
);
450 is_int(strlen(output
), len
, MSG
);
454 strcpy(tmp
, ":prefix ");
455 strcat(tmp
, MKTEXT(502));
457 is_string(tmp
, output
, MSG
);
458 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
461 static void too_long_msgf1(void)
464 char output
[2048] = { 0 };
467 rb_linebuf_newbuf(&linebuf
);
468 rb_linebuf_put_msgf(&linebuf
, ":prefix %s", MKTEXT(503));
469 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
470 rb_linebuf_donebuf(&linebuf
);
472 is_int(strlen(output
), len
, MSG
);
476 strcpy(tmp
, ":prefix ");
477 strcat(tmp
, MKTEXT(503));
478 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
480 is_string(tmp
, output
, MSG
);
481 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
484 static void long_msgf2(void)
487 char output
[2048] = { 0 };
490 rb_linebuf_newbuf(&linebuf
);
491 rb_linebuf_put_msgf(&linebuf
, ":prefix %s", MKTEXT(502));
492 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
493 rb_linebuf_donebuf(&linebuf
);
495 is_int(strlen(output
), len
, MSG
);
499 strcpy(tmp
, ":prefix ");
500 strcat(tmp
, MKTEXT(502));
502 is_string(tmp
, output
, MSG
);
503 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
506 static void too_long_msgf2(void)
509 char output
[2048] = { 0 };
512 rb_linebuf_newbuf(&linebuf
);
513 rb_linebuf_put_msgf(&linebuf
, ":prefix %s", MKTEXT(503));
514 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
515 rb_linebuf_donebuf(&linebuf
);
517 is_int(strlen(output
), len
, MSG
);
521 strcpy(tmp
, ":prefix ");
522 strcat(tmp
, MKTEXT(503));
523 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
525 is_string(tmp
, output
, MSG
);
526 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
529 static void basic_vmsg1(void)
532 char output
[2048] = { 0 };
535 rb_linebuf_newbuf(&linebuf
);
536 _rb_linebuf_put_vmsg(&linebuf
, ":prefix test %s %d", "TEST", 42);
537 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
538 rb_linebuf_donebuf(&linebuf
);
540 is_int(strlen(output
), len
, MSG
);
541 is_string(":prefix test TEST 42" CRLF
, output
, MSG
);
544 static void long_vmsg1(void)
547 char output
[2048] = { 0 };
550 rb_linebuf_newbuf(&linebuf
);
551 _rb_linebuf_put_vmsg(&linebuf
, ":prefix %s", MKTEXT(502));
552 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
553 rb_linebuf_donebuf(&linebuf
);
555 is_int(strlen(output
), len
, MSG
);
559 strcpy(tmp
, ":prefix ");
560 strcat(tmp
, MKTEXT(502));
562 is_string(tmp
, output
, MSG
);
563 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
566 static void too_long_vmsg1(void)
569 char output
[2048] = { 0 };
572 rb_linebuf_newbuf(&linebuf
);
573 _rb_linebuf_put_vmsg(&linebuf
, ":prefix %s", MKTEXT(503));
574 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
575 rb_linebuf_donebuf(&linebuf
);
577 is_int(strlen(output
), len
, MSG
);
581 strcpy(tmp
, ":prefix ");
582 strcat(tmp
, MKTEXT(503));
583 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
585 is_string(tmp
, output
, MSG
);
586 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
589 static void long_vmsg2(void)
592 char output
[2048] = { 0 };
595 rb_linebuf_newbuf(&linebuf
);
596 _rb_linebuf_put_vmsg(&linebuf
, ":prefix %s", MKTEXT(502));
597 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
598 rb_linebuf_donebuf(&linebuf
);
600 is_int(strlen(output
), len
, MSG
);
604 strcpy(tmp
, ":prefix ");
605 strcat(tmp
, MKTEXT(502));
607 is_string(tmp
, output
, MSG
);
608 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
611 static void too_long_vmsg2(void)
614 char output
[2048] = { 0 };
617 rb_linebuf_newbuf(&linebuf
);
618 _rb_linebuf_put_vmsg(&linebuf
, ":prefix %s", MKTEXT(503));
619 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
620 rb_linebuf_donebuf(&linebuf
);
622 is_int(strlen(output
), len
, MSG
);
626 strcpy(tmp
, ":prefix ");
627 strcat(tmp
, MKTEXT(503));
628 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
630 is_string(tmp
, output
, MSG
);
631 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
634 static void basic_vmsg_prefixf1(void)
637 char output
[2048] = { 0 };
640 rb_linebuf_newbuf(&linebuf
);
641 _rb_linebuf_put_vmsg_prefixf(&linebuf
, ":pre%d ", "test %s %d", "TEST", 42);
642 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
643 rb_linebuf_donebuf(&linebuf
);
645 is_int(strlen(output
), len
, MSG
);
646 is_string(":pre300 test TEST 42" CRLF
, output
, MSG
);
649 static void long_vmsg_prefixf1(void)
652 char output
[2048] = { 0 };
655 rb_linebuf_newbuf(&linebuf
);
656 _rb_linebuf_put_vmsg_prefixf(&linebuf
, ":pre%d ", "%s", MKTEXT(502));
657 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
658 rb_linebuf_donebuf(&linebuf
);
660 is_int(strlen(output
), len
, MSG
);
664 strcpy(tmp
, ":pre300 ");
665 strcat(tmp
, MKTEXT(502));
667 is_string(tmp
, output
, MSG
);
668 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
671 static void too_long_vmsg_prefixf1(void)
674 char output
[2048] = { 0 };
677 rb_linebuf_newbuf(&linebuf
);
678 _rb_linebuf_put_vmsg_prefixf(&linebuf
, ":pre%d ", "%s", MKTEXT(503));
679 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
680 rb_linebuf_donebuf(&linebuf
);
682 is_int(strlen(output
), len
, MSG
);
686 strcpy(tmp
, ":pre300 ");
687 strcat(tmp
, MKTEXT(503));
688 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
690 is_string(tmp
, output
, MSG
);
691 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
694 static void long_vmsg_prefixf2(void)
697 char output
[2048] = { 0 };
700 rb_linebuf_newbuf(&linebuf
);
701 _rb_linebuf_put_vmsg_prefixf(&linebuf
, ":pre%d ", "%s", MKTEXT(502));
702 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
703 rb_linebuf_donebuf(&linebuf
);
705 is_int(strlen(output
), len
, MSG
);
709 strcpy(tmp
, ":pre300 ");
710 strcat(tmp
, MKTEXT(502));
712 is_string(tmp
, output
, MSG
);
713 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
716 static void too_long_vmsg_prefixf2(void)
719 char output
[2048] = { 0 };
722 rb_linebuf_newbuf(&linebuf
);
723 _rb_linebuf_put_vmsg_prefixf(&linebuf
, ":pre%d ", "%s", MKTEXT(503));
724 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
725 rb_linebuf_donebuf(&linebuf
);
727 is_int(strlen(output
), len
, MSG
);
731 strcpy(tmp
, ":pre300 ");
732 strcat(tmp
, MKTEXT(503));
733 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
735 is_string(tmp
, output
, MSG
);
736 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
739 static void long_vmsg_prefixf3(void)
742 char output
[2048] = { 0 };
743 char prefix
[2048] = { 0 };
746 strcpy(prefix
, MKTEXT(507));
747 strcat(prefix
, "%d");
749 rb_linebuf_newbuf(&linebuf
);
750 _rb_linebuf_put_vmsg_prefixf(&linebuf
, prefix
, "%s", MKTEXT(500));
751 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
752 rb_linebuf_donebuf(&linebuf
);
754 is_int(strlen(output
), len
, MSG
);
758 strcpy(tmp
, MKTEXT(507));
761 is_string(tmp
, output
, MSG
);
762 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
765 static void too_long_vmsg_prefixf3(void)
768 char output
[2048] = { 0 };
769 char prefix
[2048] = { 0 };
772 strcpy(prefix
, MKTEXT(508));
773 strcat(prefix
, "%d");
775 rb_linebuf_newbuf(&linebuf
);
776 _rb_linebuf_put_vmsg_prefixf(&linebuf
, prefix
, "%s", MKTEXT(500));
777 len
= rb_linebuf_get(&linebuf
, output
, sizeof(output
), 0, 1);
778 rb_linebuf_donebuf(&linebuf
);
780 is_int(strlen(output
), len
, MSG
);
784 strcpy(tmp
, MKTEXT(508));
786 tmp
[strlen(tmp
) - 1] = 0; /* truncated message */
788 is_string(tmp
, output
, MSG
);
789 is_int(DATALEN
+ strlen(CRLF
), strlen(output
), MSG
);
792 int main(int argc
, char *argv
[])
794 memset(&me
, 0, sizeof(me
));
795 strcpy(me
.name
, "me.name.");
797 strcpy(long_tags
, "@");
798 strcat(long_tags
, MKTEXT(510));
799 strcat(long_tags
, " ");
801 /* no space for any additional message */
802 strcpy(long_prefix
, "@");
803 strcat(long_prefix
, MKTEXT(510));
804 strcat(long_prefix
, " ");
805 strcat(long_prefix
, MKTEXT(510));
807 strcpy(long_prefixf
, "@");
808 strcat(long_prefixf
, MKTEXT(510));
809 strcat(long_prefixf
, " ");
810 strcat(long_prefixf
, MKTEXT(507));
811 strcat(long_prefixf
, "%d");
813 rb_lib_init(NULL
, NULL
, NULL
, 0, 1024, DNODE_HEAP_SIZE
, FD_HEAP_SIZE
);
814 rb_linebuf_init(LINEBUF_HEAP_SIZE
);
818 is_int(512, TAGSLEN
, MSG
);
819 is_int(510, DATALEN
, MSG
);
821 is_int(TAGSLEN
, strlen(long_tags
), MSG
);
822 is_int(TAGSLEN
+ DATALEN
, strlen(long_prefix
), MSG
);
823 /* this is a format string, "%d" -> "300", so 1 char short */
824 is_int(TAGSLEN
+ DATALEN
- 1, strlen(long_prefixf
), MSG
);
826 basic_vtags_prefix1();
827 long_vtags_prefix1();
828 too_long_vtags_prefix1();
829 long_vtags_prefix2();
830 too_long_vtags_prefix2();
831 long_vtags_prefix3();
832 too_long_vtags_prefix3();
834 basic_vtags_prefixf1();
835 long_vtags_prefixf1();
836 too_long_vtags_prefixf1();
837 long_vtags_prefixf2();
838 too_long_vtags_prefixf2();
839 long_vtags_prefixf3();
840 too_long_vtags_prefixf3();
854 basic_vmsg_prefixf1();
855 long_vmsg_prefixf1();
856 too_long_vmsg_prefixf1();
857 long_vmsg_prefixf2();
858 too_long_vmsg_prefixf2();
859 long_vmsg_prefixf3();
860 too_long_vmsg_prefixf3();