1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int
do_test(void)6 do_test (void)
7 {
8 size_t instances = 16384;
9 #define X0 "\n%1$s\n" "%1$s" "%2$s" "%2$s" "%3$s" "%4$s" "%5$d" "%5$d"
10 const char *item = "\na\nabbcd55";
11 #define X3 X0 X0 X0 X0 X0 X0 X0 X0
12 #define X6 X3 X3 X3 X3 X3 X3 X3 X3
13 #define X9 X6 X6 X6 X6 X6 X6 X6 X6
14 #define X12 X9 X9 X9 X9 X9 X9 X9 X9
15 #define X14 X12 X12 X12 X12
16 #define TRAILER "%%%%%%%%%%%%%%%%%%%%%%%%%%"
17 #define TRAILER2 TRAILER TRAILER
18 size_t length = instances * strlen (item) + strlen (TRAILER) + 1;
19
20 char *buf = malloc (length + 1);
21 snprintf (buf, length + 1,
22 X14 TRAILER2 "\n",
23 "a", "b", "c", "d", 5);
24
25 const char *p = buf;
26 size_t i;
27 for (i = 0; i < instances; ++i)
28 {
29 const char *expected;
30 for (expected = item; *expected; ++expected)
31 {
32 if (*p != *expected)
33 {
34 printf ("mismatch at offset %zu (%zu): expected %d, got %d\n",
35 (size_t) (p - buf), i, *expected & 0xFF, *p & 0xFF);
36 return 1;
37 }
38 ++p;
39 }
40 }
41 if (strcmp (p, TRAILER "\n") != 0)
42 {
43 printf ("mismatch at trailer: [%s]\n", p);
44 return 1;
45 }
46 free (buf);
47 return 0;
48 }
49 #define TEST_FUNCTION do_test ()
50 #include "../test-skeleton.c"
51