This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <uchar.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (c32srtombs, size_t,
25 (char *, const char32_t **, size_t, mbstate_t *));
26
27 #include <locale.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "macros.h"
32
33 int
34 main (int argc, char *argv[])
35 {
36
37 if (setlocale (LC_ALL, "") == NULL)
38 return 1;
39
40 if (argc > 1)
41 {
42 char32_t input[10];
43 size_t n;
44 const char32_t *src;
45 #define BUFSIZE 20
46 char buf[BUFSIZE];
47 size_t ret;
48
49 {
50 size_t i;
51 for (i = 0; i < BUFSIZE; i++)
52 buf[i] = '_';
53 }
54
55 switch (argv[1][0])
56 {
57 case '1':
58
59 {
60 const char original[] = "B\374\337er";
61
62 ret = mbstoc32s (input, original, 10);
63 ASSERT (ret == 5);
64
65 for (n = 0; n < 10; n++)
66 {
67 src = input;
68 ret = c32srtombs (NULL, &src, n, NULL);
69 ASSERT (ret == 5);
70 ASSERT (src == input);
71
72 src = input;
73 ret = c32srtombs (buf, &src, n, NULL);
74 ASSERT (ret == (n <= 5 ? n : 5));
75 ASSERT (src == (n <= 5 ? input + n : NULL));
76 ASSERT (memcmp (buf, original, ret) == 0);
77 if (src == NULL)
78 ASSERT (buf[ret] == '\0');
79 ASSERT (buf[ret + (src == NULL) + 0] == '_');
80 ASSERT (buf[ret + (src == NULL) + 1] == '_');
81 ASSERT (buf[ret + (src == NULL) + 2] == '_');
82 }
83 }
84 break;
85
86 case '2':
87
88 {
89 const char original[] = "s\303\274\303\237\360\237\230\213!";
90
91 ret = mbstoc32s (input, original, 10);
92 ASSERT (ret == 5);
93
94 for (n = 0; n < 15; n++)
95 {
96 src = input;
97 ret = c32srtombs (NULL, &src, n, NULL);
98 ASSERT (ret == 10);
99 ASSERT (src == input);
100
101 src = input;
102 ret = c32srtombs (buf, &src, n, NULL);
103 ASSERT (ret == (n < 1 ? n :
104 n < 3 ? 1 :
105 n < 5 ? 3 :
106 n < 9 ? 5 :
107 n <= 10 ? n : 10));
108 ASSERT (src == (n < 1 ? input + n :
109 n < 3 ? input + 1 :
110 n < 5 ? input + 2 :
111 n < 9 ? input + 3 :
112 n <= 10 ? input + (n - 5) : NULL));
113 ASSERT (memcmp (buf, original, ret) == 0);
114 if (src == NULL)
115 ASSERT (buf[ret] == '\0');
116 ASSERT (buf[ret + (src == NULL) + 0] == '_');
117 ASSERT (buf[ret + (src == NULL) + 1] == '_');
118 ASSERT (buf[ret + (src == NULL) + 2] == '_');
119 }
120 }
121 break;
122
123 case '3':
124
125 {
126 const char original[] = "<\306\374\313\334\270\354>";
127
128 ret = mbstoc32s (input, original, 10);
129 ASSERT (ret == 5);
130
131 for (n = 0; n < 10; n++)
132 {
133 src = input;
134 ret = c32srtombs (NULL, &src, n, NULL);
135 ASSERT (ret == 8);
136 ASSERT (src == input);
137
138 src = input;
139 ret = c32srtombs (buf, &src, n, NULL);
140 ASSERT (ret == (n < 1 ? n :
141 n < 3 ? 1 :
142 n < 5 ? 3 :
143 n < 7 ? 5 :
144 n <= 8 ? n : 8));
145 ASSERT (src == (n < 1 ? input + n :
146 n < 3 ? input + 1 :
147 n < 5 ? input + 2 :
148 n < 7 ? input + 3 :
149 n <= 8 ? input + (n - 3) : NULL));
150 ASSERT (memcmp (buf, original, ret) == 0);
151 if (src == NULL)
152 ASSERT (buf[ret] == '\0');
153 ASSERT (buf[ret + (src == NULL) + 0] == '_');
154 ASSERT (buf[ret + (src == NULL) + 1] == '_');
155 ASSERT (buf[ret + (src == NULL) + 2] == '_');
156 }
157 }
158 break;
159
160
161 case '4':
162
163 {
164 const char original[] = "s\250\271\201\060\211\070\224\071\375\067!";
165
166 ret = mbstoc32s (input, original, 10);
167 ASSERT (ret == 5);
168
169 for (n = 0; n < 15; n++)
170 {
171 src = input;
172 ret = c32srtombs (NULL, &src, n, NULL);
173 ASSERT (ret == 12);
174 ASSERT (src == input);
175
176 src = input;
177 ret = c32srtombs (buf, &src, n, NULL);
178 ASSERT (ret == (n < 1 ? n :
179 n < 3 ? 1 :
180 n < 7 ? 3 :
181 n < 11 ? 7 :
182 n <= 12 ? n : 12));
183 ASSERT (src == (n < 1 ? input + n :
184 n < 3 ? input + 1 :
185 n < 7 ? input + 2 :
186 n < 11 ? input + 3 :
187 n <= 12 ? input + (n - 7) : NULL));
188 ASSERT (memcmp (buf, original, ret) == 0);
189 if (src == NULL)
190 ASSERT (buf[ret] == '\0');
191 ASSERT (buf[ret + (src == NULL) + 0] == '_');
192 ASSERT (buf[ret + (src == NULL) + 1] == '_');
193 ASSERT (buf[ret + (src == NULL) + 2] == '_');
194 }
195 }
196 break;
197
198 default:
199 return 1;
200 }
201
202 return 0;
203 }
204
205 return 1;
206 }