]>
Commit | Line | Data |
---|---|---|
2cc7be99 SA |
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; | |
2cc7be99 SA |
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" | |
45 | ; | |
46 | char long_tags[TAGSLEN + 1]; | |
47 | char long_prefix[TAGSLEN + DATALEN + 1]; | |
48 | char long_prefixf[TAGSLEN + DATALEN + 1]; | |
49 | ||
50 | #define MKTEXT(n) &text[sizeof(text) - ((n) + 1)] | |
51 | ||
52 | static void _rb_linebuf_put_vtags_prefix(buf_head_t *bufhead, size_t prefix_buflen, const char *prefix, const char *format, ...) | |
53 | { | |
54 | va_list args; | |
55 | ||
56 | va_start(args, format); | |
57 | rb_linebuf_put_vtags_prefix(bufhead, format, &args, prefix_buflen, prefix); | |
58 | va_end(args); | |
59 | } | |
60 | ||
61 | static void _rb_linebuf_put_vtags_prefixf(buf_head_t *bufhead, size_t prefix_buflen, const char *prefix, const char *format, ...) | |
62 | { | |
63 | va_list args; | |
64 | ||
65 | va_start(args, format); | |
66 | rb_linebuf_put_vtags_prefixf(bufhead, format, &args, prefix_buflen, prefix, 300); | |
67 | va_end(args); | |
68 | } | |
69 | ||
70 | static void _rb_linebuf_put_vmsg(buf_head_t *bufhead, const char *format, ...) | |
71 | { | |
72 | va_list args; | |
73 | ||
74 | va_start(args, format); | |
75 | rb_linebuf_put_vmsg(bufhead, format, &args); | |
76 | va_end(args); | |
77 | } | |
78 | ||
79 | static void _rb_linebuf_put_vmsg_prefixf(buf_head_t *bufhead, const char *prefix, const char *format, ...) | |
80 | { | |
81 | va_list args; | |
82 | ||
83 | va_start(args, format); | |
84 | rb_linebuf_put_vmsg_prefixf(bufhead, format, &args, prefix, 300); | |
85 | va_end(args); | |
86 | } | |
87 | ||
88 | ||
89 | #define CRLF "\r\n" | |
90 | #define SOME_TAGS "@tag1=value1;tag2=value2 " | |
91 | ||
92 | static void basic_vtags_prefix1(void) | |
93 | { | |
94 | buf_head_t linebuf; | |
95 | char output[2048] = { 0 }; | |
96 | int len; | |
97 | ||
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); | |
102 | ||
103 | is_int(strlen(output), len, MSG); | |
104 | is_string(SOME_TAGS ":prefix test TEST 42" CRLF, output, MSG); | |
105 | } | |
106 | ||
107 | static void long_vtags_prefix1(void) | |
108 | { | |
109 | buf_head_t linebuf; | |
110 | char output[2048] = { 0 }; | |
111 | int len; | |
112 | ||
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); | |
117 | ||
118 | is_int(strlen(output), len, MSG); | |
119 | ||
120 | char tmp[2048]; | |
121 | ||
122 | strcpy(tmp, SOME_TAGS ":prefix "); | |
123 | strcat(tmp, MKTEXT(502)); | |
124 | strcat(tmp, CRLF); | |
125 | is_string(tmp, output, MSG); | |
126 | is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
127 | } | |
128 | ||
129 | static void too_long_vtags_prefix1(void) | |
130 | { | |
131 | buf_head_t linebuf; | |
132 | char output[2048] = { 0 }; | |
133 | int len; | |
134 | ||
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); | |
139 | ||
140 | is_int(strlen(output), len, MSG); | |
141 | ||
142 | char tmp[2048]; | |
143 | ||
144 | strcpy(tmp, SOME_TAGS ":prefix "); | |
145 | strcat(tmp, MKTEXT(503)); | |
146 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
147 | strcat(tmp, CRLF); | |
148 | is_string(tmp, output, MSG); | |
149 | is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
150 | } | |
151 | ||
152 | static void long_vtags_prefix2(void) | |
153 | { | |
154 | buf_head_t linebuf; | |
155 | char output[2048] = { 0 }; | |
156 | char prefix[2048] = { 0 }; | |
157 | int len; | |
158 | ||
159 | strcpy(prefix, long_tags); | |
160 | strcat(prefix, ":prefix "); | |
161 | ||
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); | |
166 | ||
167 | is_int(strlen(output), len, MSG); | |
168 | ||
169 | char tmp[2048]; | |
170 | ||
171 | strcpy(tmp, long_tags); | |
172 | strcat(tmp, ":prefix "); | |
173 | strcat(tmp, MKTEXT(502)); | |
174 | strcat(tmp, CRLF); | |
175 | is_string(tmp, output, MSG); | |
176 | is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
177 | } | |
178 | ||
179 | static void too_long_vtags_prefix2(void) | |
180 | { | |
181 | buf_head_t linebuf; | |
182 | char output[2048] = { 0 }; | |
183 | char prefix[2048] = { 0 }; | |
184 | int len; | |
185 | ||
186 | strcpy(prefix, long_tags); | |
187 | strcat(prefix, ":prefix "); | |
188 | ||
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); | |
193 | ||
194 | is_int(strlen(output), len, MSG); | |
195 | ||
196 | char tmp[2048]; | |
197 | ||
198 | strcpy(tmp, long_tags); | |
199 | strcat(tmp, ":prefix "); | |
200 | strcat(tmp, MKTEXT(503)); | |
201 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
202 | strcat(tmp, CRLF); | |
203 | is_string(tmp, output, MSG); | |
204 | is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
205 | } | |
206 | ||
207 | static void long_vtags_prefix3(void) | |
208 | { | |
209 | buf_head_t linebuf; | |
210 | char output[2048] = { 0 }; | |
211 | char prefix[2048] = { 0 }; | |
212 | int len; | |
213 | ||
214 | strcpy(prefix, long_prefix); | |
215 | ||
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); | |
220 | ||
221 | is_int(strlen(output), len, MSG); | |
222 | ||
223 | char tmp[2048]; | |
224 | ||
225 | strcpy(tmp, long_prefix); | |
226 | strcat(tmp, CRLF); | |
227 | is_string(tmp, output, MSG); | |
228 | is_int(strlen(long_prefix) + strlen(CRLF), strlen(output), MSG); | |
229 | } | |
230 | ||
231 | static void too_long_vtags_prefix3(void) | |
232 | { | |
233 | buf_head_t linebuf; | |
234 | char output[2048] = { 0 }; | |
235 | char prefix[2048] = { 0 }; | |
236 | int len; | |
237 | ||
238 | strcpy(prefix, long_prefix); | |
239 | strcat(prefix, ":"); | |
240 | ||
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); | |
245 | ||
246 | is_int(strlen(output), len, MSG); | |
247 | ||
248 | char tmp[2048]; | |
249 | ||
250 | strcpy(tmp, long_prefix); | |
251 | strcat(tmp, CRLF); | |
252 | is_string(tmp, output, MSG); | |
253 | is_int(strlen(long_prefix) + strlen(CRLF), strlen(output), MSG); | |
254 | } | |
255 | ||
256 | static void basic_vtags_prefixf1(void) | |
257 | { | |
258 | buf_head_t linebuf; | |
259 | char output[2048] = { 0 }; | |
260 | int len; | |
261 | ||
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); | |
266 | ||
267 | is_int(strlen(output), len, MSG); | |
268 | is_string(SOME_TAGS ":pre300 test TEST 42" CRLF, output, MSG); | |
269 | } | |
270 | ||
271 | static void long_vtags_prefixf1(void) | |
272 | { | |
273 | buf_head_t linebuf; | |
274 | char output[2048] = { 0 }; | |
275 | int len; | |
276 | ||
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); | |
281 | ||
282 | is_int(strlen(output), len, MSG); | |
283 | ||
284 | char tmp[2048]; | |
285 | ||
286 | strcpy(tmp, SOME_TAGS ":pre300 "); | |
287 | strcat(tmp, MKTEXT(502)); | |
288 | strcat(tmp, CRLF); | |
289 | is_string(tmp, output, MSG); | |
290 | is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
291 | } | |
292 | ||
293 | static void too_long_vtags_prefixf1(void) | |
294 | { | |
295 | buf_head_t linebuf; | |
296 | char output[2048] = { 0 }; | |
297 | int len; | |
298 | ||
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); | |
303 | ||
304 | is_int(strlen(output), len, MSG); | |
305 | ||
306 | char tmp[2048]; | |
307 | ||
308 | strcpy(tmp, SOME_TAGS ":pre300 "); | |
309 | strcat(tmp, MKTEXT(503)); | |
310 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
311 | strcat(tmp, CRLF); | |
312 | is_string(tmp, output, MSG); | |
313 | is_int(strlen(SOME_TAGS) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
314 | } | |
315 | ||
316 | static void long_vtags_prefixf2(void) | |
317 | { | |
318 | buf_head_t linebuf; | |
319 | char output[2048] = { 0 }; | |
320 | char prefix[2048] = { 0 }; | |
321 | int len; | |
322 | ||
323 | strcpy(prefix, long_tags); | |
324 | strcat(prefix, ":pre%d "); | |
325 | ||
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); | |
330 | ||
331 | is_int(strlen(output), len, MSG); | |
332 | ||
333 | char tmp[2048]; | |
334 | ||
335 | strcpy(tmp, long_tags); | |
336 | strcat(tmp, ":pre300 "); | |
337 | strcat(tmp, MKTEXT(502)); | |
338 | strcat(tmp, CRLF); | |
339 | is_string(tmp, output, MSG); | |
340 | is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
341 | } | |
342 | ||
343 | static void too_long_vtags_prefixf2(void) | |
344 | { | |
345 | buf_head_t linebuf; | |
346 | char output[2048] = { 0 }; | |
347 | char prefix[2048] = { 0 }; | |
348 | int len; | |
349 | ||
350 | strcpy(prefix, long_tags); | |
351 | strcat(prefix, ":pre%d "); | |
352 | ||
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); | |
357 | ||
358 | is_int(strlen(output), len, MSG); | |
359 | ||
360 | char tmp[2048]; | |
361 | ||
362 | strcpy(tmp, long_tags); | |
363 | strcat(tmp, ":pre300 "); | |
364 | strcat(tmp, MKTEXT(503)); | |
365 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
366 | strcat(tmp, CRLF); | |
367 | is_string(tmp, output, MSG); | |
368 | is_int(strlen(long_tags) + DATALEN + strlen(CRLF), strlen(output), MSG); | |
369 | } | |
370 | ||
371 | static void long_vtags_prefixf3(void) | |
372 | { | |
373 | buf_head_t linebuf; | |
374 | char output[2048] = { 0 }; | |
375 | char prefix[2048] = { 0 }; | |
376 | int len; | |
377 | ||
378 | strcpy(prefix, long_prefixf); | |
379 | ||
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); | |
384 | ||
385 | is_int(strlen(output), len, MSG); | |
386 | ||
387 | char tmp[2048]; | |
388 | ||
389 | strcpy(tmp, long_prefixf); | |
390 | tmp[strlen(tmp) - 2] = 0; | |
391 | strcat(tmp, "300"); | |
392 | strcat(tmp, CRLF); | |
393 | is_string(tmp, output, MSG); | |
394 | is_int(strlen(long_prefixf) + 1 + strlen(CRLF), strlen(output), MSG); | |
395 | } | |
396 | ||
397 | static void too_long_vtags_prefixf3(void) | |
398 | { | |
399 | buf_head_t linebuf; | |
400 | char output[2048] = { 0 }; | |
401 | char prefix[2048] = { 0 }; | |
402 | int len; | |
403 | ||
404 | strcpy(prefix, long_prefixf); | |
405 | strcat(prefix, ":"); | |
406 | ||
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); | |
411 | ||
412 | is_int(strlen(output), len, MSG); | |
413 | ||
414 | char tmp[2048]; | |
415 | ||
416 | strcpy(tmp, long_prefixf); | |
417 | tmp[strlen(tmp) - 2] = 0; | |
418 | strcat(tmp, "300"); | |
419 | strcat(tmp, CRLF); | |
420 | is_string(tmp, output, MSG); | |
421 | is_int(strlen(long_prefixf) + 1 + strlen(CRLF), strlen(output), MSG); | |
422 | } | |
423 | ||
424 | static void basic_msgf1(void) | |
425 | { | |
426 | buf_head_t linebuf; | |
427 | char output[2048] = { 0 }; | |
428 | int len; | |
429 | ||
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); | |
434 | ||
435 | is_int(strlen(output), len, MSG); | |
436 | is_string(":prefix test TEST 42" CRLF, output, MSG); | |
437 | } | |
438 | ||
439 | static void long_msgf1(void) | |
440 | { | |
441 | buf_head_t linebuf; | |
442 | char output[2048] = { 0 }; | |
443 | int len; | |
444 | ||
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); | |
449 | ||
450 | is_int(strlen(output), len, MSG); | |
451 | ||
452 | char tmp[2048]; | |
453 | ||
454 | strcpy(tmp, ":prefix "); | |
455 | strcat(tmp, MKTEXT(502)); | |
456 | strcat(tmp, CRLF); | |
457 | is_string(tmp, output, MSG); | |
458 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
459 | } | |
460 | ||
461 | static void too_long_msgf1(void) | |
462 | { | |
463 | buf_head_t linebuf; | |
464 | char output[2048] = { 0 }; | |
465 | int len; | |
466 | ||
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); | |
471 | ||
472 | is_int(strlen(output), len, MSG); | |
473 | ||
474 | char tmp[2048]; | |
475 | ||
476 | strcpy(tmp, ":prefix "); | |
477 | strcat(tmp, MKTEXT(503)); | |
478 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
479 | strcat(tmp, CRLF); | |
480 | is_string(tmp, output, MSG); | |
481 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
482 | } | |
483 | ||
484 | static void long_msgf2(void) | |
485 | { | |
486 | buf_head_t linebuf; | |
487 | char output[2048] = { 0 }; | |
2cc7be99 SA |
488 | int len; |
489 | ||
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); | |
494 | ||
495 | is_int(strlen(output), len, MSG); | |
496 | ||
497 | char tmp[2048]; | |
498 | ||
499 | strcpy(tmp, ":prefix "); | |
500 | strcat(tmp, MKTEXT(502)); | |
501 | strcat(tmp, CRLF); | |
502 | is_string(tmp, output, MSG); | |
503 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
504 | } | |
505 | ||
506 | static void too_long_msgf2(void) | |
507 | { | |
508 | buf_head_t linebuf; | |
509 | char output[2048] = { 0 }; | |
2cc7be99 SA |
510 | int len; |
511 | ||
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); | |
516 | ||
517 | is_int(strlen(output), len, MSG); | |
518 | ||
519 | char tmp[2048]; | |
520 | ||
521 | strcpy(tmp, ":prefix "); | |
522 | strcat(tmp, MKTEXT(503)); | |
523 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
524 | strcat(tmp, CRLF); | |
525 | is_string(tmp, output, MSG); | |
526 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
527 | } | |
528 | ||
529 | static void basic_vmsg1(void) | |
530 | { | |
531 | buf_head_t linebuf; | |
532 | char output[2048] = { 0 }; | |
533 | int len; | |
534 | ||
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); | |
539 | ||
540 | is_int(strlen(output), len, MSG); | |
541 | is_string(":prefix test TEST 42" CRLF, output, MSG); | |
542 | } | |
543 | ||
544 | static void long_vmsg1(void) | |
545 | { | |
546 | buf_head_t linebuf; | |
547 | char output[2048] = { 0 }; | |
548 | int len; | |
549 | ||
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); | |
554 | ||
555 | is_int(strlen(output), len, MSG); | |
556 | ||
557 | char tmp[2048]; | |
558 | ||
559 | strcpy(tmp, ":prefix "); | |
560 | strcat(tmp, MKTEXT(502)); | |
561 | strcat(tmp, CRLF); | |
562 | is_string(tmp, output, MSG); | |
563 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
564 | } | |
565 | ||
566 | static void too_long_vmsg1(void) | |
567 | { | |
568 | buf_head_t linebuf; | |
569 | char output[2048] = { 0 }; | |
570 | int len; | |
571 | ||
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); | |
576 | ||
577 | is_int(strlen(output), len, MSG); | |
578 | ||
579 | char tmp[2048]; | |
580 | ||
581 | strcpy(tmp, ":prefix "); | |
582 | strcat(tmp, MKTEXT(503)); | |
583 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
584 | strcat(tmp, CRLF); | |
585 | is_string(tmp, output, MSG); | |
586 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
587 | } | |
588 | ||
589 | static void long_vmsg2(void) | |
590 | { | |
591 | buf_head_t linebuf; | |
592 | char output[2048] = { 0 }; | |
2cc7be99 SA |
593 | int len; |
594 | ||
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); | |
599 | ||
600 | is_int(strlen(output), len, MSG); | |
601 | ||
602 | char tmp[2048]; | |
603 | ||
604 | strcpy(tmp, ":prefix "); | |
605 | strcat(tmp, MKTEXT(502)); | |
606 | strcat(tmp, CRLF); | |
607 | is_string(tmp, output, MSG); | |
608 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
609 | } | |
610 | ||
611 | static void too_long_vmsg2(void) | |
612 | { | |
613 | buf_head_t linebuf; | |
614 | char output[2048] = { 0 }; | |
2cc7be99 SA |
615 | int len; |
616 | ||
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); | |
621 | ||
622 | is_int(strlen(output), len, MSG); | |
623 | ||
624 | char tmp[2048]; | |
625 | ||
626 | strcpy(tmp, ":prefix "); | |
627 | strcat(tmp, MKTEXT(503)); | |
628 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
629 | strcat(tmp, CRLF); | |
630 | is_string(tmp, output, MSG); | |
631 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
632 | } | |
633 | ||
634 | static void basic_vmsg_prefixf1(void) | |
635 | { | |
636 | buf_head_t linebuf; | |
637 | char output[2048] = { 0 }; | |
638 | int len; | |
639 | ||
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); | |
644 | ||
645 | is_int(strlen(output), len, MSG); | |
646 | is_string(":pre300 test TEST 42" CRLF, output, MSG); | |
647 | } | |
648 | ||
649 | static void long_vmsg_prefixf1(void) | |
650 | { | |
651 | buf_head_t linebuf; | |
652 | char output[2048] = { 0 }; | |
653 | int len; | |
654 | ||
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); | |
659 | ||
660 | is_int(strlen(output), len, MSG); | |
661 | ||
662 | char tmp[2048]; | |
663 | ||
664 | strcpy(tmp, ":pre300 "); | |
665 | strcat(tmp, MKTEXT(502)); | |
666 | strcat(tmp, CRLF); | |
667 | is_string(tmp, output, MSG); | |
668 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
669 | } | |
670 | ||
671 | static void too_long_vmsg_prefixf1(void) | |
672 | { | |
673 | buf_head_t linebuf; | |
674 | char output[2048] = { 0 }; | |
675 | int len; | |
676 | ||
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); | |
681 | ||
682 | is_int(strlen(output), len, MSG); | |
683 | ||
684 | char tmp[2048]; | |
685 | ||
686 | strcpy(tmp, ":pre300 "); | |
687 | strcat(tmp, MKTEXT(503)); | |
688 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
689 | strcat(tmp, CRLF); | |
690 | is_string(tmp, output, MSG); | |
691 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
692 | } | |
693 | ||
694 | static void long_vmsg_prefixf2(void) | |
695 | { | |
696 | buf_head_t linebuf; | |
697 | char output[2048] = { 0 }; | |
698 | int len; | |
699 | ||
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); | |
704 | ||
705 | is_int(strlen(output), len, MSG); | |
706 | ||
707 | char tmp[2048]; | |
708 | ||
709 | strcpy(tmp, ":pre300 "); | |
710 | strcat(tmp, MKTEXT(502)); | |
711 | strcat(tmp, CRLF); | |
712 | is_string(tmp, output, MSG); | |
713 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
714 | } | |
715 | ||
716 | static void too_long_vmsg_prefixf2(void) | |
717 | { | |
718 | buf_head_t linebuf; | |
719 | char output[2048] = { 0 }; | |
720 | int len; | |
721 | ||
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); | |
726 | ||
727 | is_int(strlen(output), len, MSG); | |
728 | ||
729 | char tmp[2048]; | |
730 | ||
731 | strcpy(tmp, ":pre300 "); | |
732 | strcat(tmp, MKTEXT(503)); | |
733 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
734 | strcat(tmp, CRLF); | |
735 | is_string(tmp, output, MSG); | |
736 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
737 | } | |
738 | ||
739 | static void long_vmsg_prefixf3(void) | |
740 | { | |
741 | buf_head_t linebuf; | |
742 | char output[2048] = { 0 }; | |
743 | char prefix[2048] = { 0 }; | |
744 | int len; | |
745 | ||
746 | strcpy(prefix, MKTEXT(507)); | |
747 | strcat(prefix, "%d"); | |
748 | ||
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); | |
753 | ||
754 | is_int(strlen(output), len, MSG); | |
755 | ||
756 | char tmp[2048]; | |
757 | ||
758 | strcpy(tmp, MKTEXT(507)); | |
759 | strcat(tmp, "300"); | |
760 | strcat(tmp, CRLF); | |
761 | is_string(tmp, output, MSG); | |
762 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
763 | } | |
764 | ||
765 | static void too_long_vmsg_prefixf3(void) | |
766 | { | |
767 | buf_head_t linebuf; | |
768 | char output[2048] = { 0 }; | |
769 | char prefix[2048] = { 0 }; | |
770 | int len; | |
771 | ||
772 | strcpy(prefix, MKTEXT(508)); | |
773 | strcat(prefix, "%d"); | |
774 | ||
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); | |
779 | ||
780 | is_int(strlen(output), len, MSG); | |
781 | ||
782 | char tmp[2048]; | |
783 | ||
784 | strcpy(tmp, MKTEXT(508)); | |
785 | strcat(tmp, "300"); | |
786 | tmp[strlen(tmp) - 1] = 0; /* truncated message */ | |
787 | strcat(tmp, CRLF); | |
788 | is_string(tmp, output, MSG); | |
789 | is_int(DATALEN + strlen(CRLF), strlen(output), MSG); | |
790 | } | |
791 | ||
792 | int main(int argc, char *argv[]) | |
793 | { | |
794 | memset(&me, 0, sizeof(me)); | |
795 | strcpy(me.name, "me.name."); | |
796 | ||
797 | strcpy(long_tags, "@"); | |
798 | strcat(long_tags, MKTEXT(510)); | |
799 | strcat(long_tags, " "); | |
800 | ||
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)); | |
806 | ||
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"); | |
812 | ||
813 | rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE); | |
814 | rb_linebuf_init(LINEBUF_HEAP_SIZE); | |
815 | ||
816 | plan_lazy(); | |
817 | ||
818 | is_int(512, TAGSLEN, MSG); | |
819 | is_int(510, DATALEN, MSG); | |
820 | ||
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); | |
825 | ||
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(); | |
833 | ||
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(); | |
841 | ||
842 | basic_msgf1(); | |
843 | long_msgf1(); | |
844 | too_long_msgf1(); | |
845 | long_msgf2(); | |
846 | too_long_msgf2(); | |
847 | ||
848 | basic_vmsg1(); | |
849 | long_vmsg1(); | |
850 | too_long_vmsg1(); | |
851 | long_vmsg2(); | |
852 | too_long_vmsg2(); | |
853 | ||
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(); | |
861 | ||
862 | return 0; | |
863 | } |