* string/strverscmp.c (__strverscmp): Fix last cleanups.
[glibc/pb-stable.git] / stdio-common / scanf13.c
blobe53cde29c79c86942376947c6f19240b452b42a9
1 #include <locale.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <wchar.h>
7 int
8 main (void)
10 char *sp1, *sp2, *sp3, *sp4;
11 wchar_t *lsp1, *lsp2, *lsp3, *lsp4;
12 int result = 0;
13 char buf[2048+64];
14 wchar_t wbuf[2048+64];
15 size_t i;
17 #define FAIL() \
18 do { \
19 result = 1; \
20 printf ("test at line %d failed\n", __LINE__); \
21 } while (0)
23 setlocale (LC_ALL, "de_DE.UTF-8");
24 if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-B",
25 "A%ms%10ms%4m[bcd]%4mcB", &sp1, &sp2, &sp3, &sp4) != 4)
26 FAIL ();
27 else
29 if (strcmp (sp1, "\xc3\x84-") != 0)
30 FAIL ();
31 free (sp1);
32 if (strcmp (sp2, "\xc3\x84-abcdefb") != 0)
33 FAIL ();
34 free (sp2);
35 if (strcmp (sp3, "cd") != 0)
36 FAIL ();
37 free (sp3);
38 if (memcmp (sp4, "\t\xc3\x84-", 4) != 0)
39 FAIL ();
40 free (sp4);
43 if (sscanf ("A \xc3\x84-\t\t\xc3\x84-abcdefbcd\t\xc3\x84-BB",
44 "A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4)
45 FAIL ();
46 else
48 if (wcscmp (lsp1, L"\xc4-") != 0)
49 FAIL ();
50 free (lsp1);
51 if (wcscmp (lsp2, L"\xc4-abcdefbc") != 0)
52 FAIL ();
53 free (lsp2);
54 if (wcscmp (lsp3, L"d") != 0)
55 FAIL ();
56 free (lsp3);
57 if (memcmp (lsp4, L"\t\xc4-B", 4 * sizeof (wchar_t)) != 0)
58 FAIL ();
59 free (lsp4);
62 memset (buf, '/', sizeof (buf));
63 buf[0] = '\t';
64 buf[1] = ' ';
65 buf[2] = 0xc3;
66 buf[3] = 0x84;
67 buf[2048] = 0xc3;
68 buf[2049] = 0x84;
69 buf[2058] = '\t';
70 buf[2059] = 'a';
71 if (sscanf (buf, "%ms%mc", &sp1, &sp2) != 2)
72 FAIL ();
73 else
75 if (sp1[0] != '\xc3' || sp1[1] != '\x84'
76 || sp1[2046] != '\xc3' || sp1[2047] != '\x84'
77 || sp1[2056] != '\0')
78 FAIL ();
79 sp1[2046] = '/';
80 sp1[2047] = '/';
81 for (i = 2; i < 2056; i++)
82 if (sp1[i] != '/')
83 FAIL ();
84 free (sp1);
85 if (sp2[0] != '\t')
86 FAIL ();
87 free (sp2);
89 if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2)
90 FAIL ();
91 else
93 if (sp3[0] != '\xc3' || sp3[1] != '\x84'
94 || sp3[2046] != '\xc3' || sp3[2047] != '\x84'
95 || sp3[2048] != '\0')
96 FAIL ();
97 for (i = 2; i < 2046; i++)
98 if (sp3[i] != '/')
99 FAIL ();
100 free (sp3);
101 if (sp4[0] != '/')
102 FAIL ();
103 free (sp4);
105 if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4)
106 != 4)
107 FAIL ();
108 else
110 if (memcmp (sp1, "\t \xc3\x84", 4) != 0)
111 FAIL ();
112 free (sp1);
113 for (i = 0; i < 1500; i++)
114 if (sp2[i] != '/')
115 FAIL ();
116 if (sp2[1500] != '\0')
117 FAIL ();
118 free (sp2);
119 for (i = 0; i < 544; i++)
120 if (sp3[i] != '/')
121 FAIL ();
122 if (sp3[544] != '\0')
123 FAIL ();
124 free (sp3);
125 if (memcmp (sp4, "\xc3\x84/", 3) != 0)
126 FAIL ();
127 free (sp4);
129 if (sscanf (buf, "%mS%mC", &lsp1, &lsp2) != 2)
130 FAIL ();
131 else
133 if (lsp1[0] != L'\xc4' || lsp1[2045] != L'\xc4'
134 || lsp1[2054] != L'\0')
135 FAIL ();
136 lsp1[2045] = L'/';
137 for (i = 1; i < 2054; i++)
138 if (lsp1[i] != L'/')
139 FAIL ();
140 free (lsp1);
141 if (lsp2[0] != L'\t')
142 FAIL ();
143 free (lsp2);
145 if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2)
146 FAIL ();
147 else
149 if (lsp3[0] != L'\xc4' || lsp3[2045] != L'\xc4'
150 || lsp3[2048] != L'\0')
151 FAIL ();
152 lsp3[2045] = L'/';
153 for (i = 1; i < 2048; i++)
154 if (lsp3[i] != L'/')
155 FAIL ();
156 free (lsp3);
157 if (lsp4[0] != L'/')
158 FAIL ();
159 free (lsp4);
161 if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc",
162 &lsp1, &lsp2, &lsp3, &lsp4) != 4)
163 FAIL ();
164 else
166 if (memcmp (lsp1, L"\t \xc4/", 4 * sizeof (wchar_t)) != 0)
167 FAIL ();
168 free (lsp1);
169 for (i = 0; i < 1500; i++)
170 if (lsp2[i] != L'/')
171 FAIL ();
172 if (lsp2[1500] != L'\0')
173 FAIL ();
174 free (lsp2);
175 for (i = 0; i < 543; i++)
176 if (lsp3[i] != L'/')
177 FAIL ();
178 if (lsp3[543] != L'\0')
179 FAIL ();
180 free (lsp3);
181 if (memcmp (lsp4, L"\xc4//", 3 * sizeof (wchar_t)) != 0)
182 FAIL ();
183 free (lsp4);
186 return result;