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 (c32stombs, size_t,
25 (char *, const char32_t *, size_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 #define BUFSIZE 20
45 char buf[BUFSIZE];
46 size_t ret;
47
48 {
49 size_t i;
50 for (i = 0; i < BUFSIZE; i++)
51 buf[i] = '_';
52 }
53
54 switch (argv[1][0])
55 {
56 case '1':
57
58 {
59 const char original[] = "B\374\337er";
60
61 ret = mbstoc32s (input, original, 10);
62 ASSERT (ret == 5);
63
64 for (n = 0; n < 10; n++)
65 {
66 ret = c32stombs (NULL, input, n);
67 ASSERT (ret == 5);
68
69 ret = c32stombs (buf, input, n);
70 ASSERT (ret == (n <= 5 ? n : 5));
71 ASSERT (memcmp (buf, original, ret) == 0);
72 if (n > 5)
73 ASSERT (buf[ret] == '\0');
74 ASSERT (buf[ret + (n > 5) + 0] == '_');
75 ASSERT (buf[ret + (n > 5) + 1] == '_');
76 ASSERT (buf[ret + (n > 5) + 2] == '_');
77 }
78 }
79 break;
80
81 case '2':
82
83 {
84 const char original[] = "s\303\274\303\237\360\237\230\213!";
85
86 ret = mbstoc32s (input, original, 10);
87 ASSERT (ret == 5);
88
89 for (n = 0; n < 15; n++)
90 {
91 ret = c32stombs (NULL, input, n);
92 ASSERT (ret == 10);
93
94 ret = c32stombs (buf, input, n);
95 ASSERT (ret == (n < 1 ? n :
96 n < 3 ? 1 :
97 n < 5 ? 3 :
98 n < 9 ? 5 :
99 n <= 10 ? n : 10));
100 ASSERT (memcmp (buf, original, ret) == 0);
101 if (n > 10)
102 ASSERT (buf[ret] == '\0');
103 ASSERT (buf[ret + (n > 10) + 0] == '_');
104 ASSERT (buf[ret + (n > 10) + 1] == '_');
105 ASSERT (buf[ret + (n > 10) + 2] == '_');
106 }
107 }
108 break;
109
110 case '3':
111
112 {
113 const char original[] = "<\306\374\313\334\270\354>";
114
115 ret = mbstoc32s (input, original, 10);
116 ASSERT (ret == 5);
117
118 for (n = 0; n < 10; n++)
119 {
120 ret = c32stombs (NULL, input, n);
121 ASSERT (ret == 8);
122
123 ret = c32stombs (buf, input, n);
124 ASSERT (ret == (n < 1 ? n :
125 n < 3 ? 1 :
126 n < 5 ? 3 :
127 n < 7 ? 5 :
128 n <= 8 ? n : 8));
129 ASSERT (memcmp (buf, original, ret) == 0);
130 if (n > 8)
131 ASSERT (buf[ret] == '\0');
132 ASSERT (buf[ret + (n > 8) + 0] == '_');
133 ASSERT (buf[ret + (n > 8) + 1] == '_');
134 ASSERT (buf[ret + (n > 8) + 2] == '_');
135 }
136 }
137 break;
138
139
140 case '4':
141
142 {
143 const char original[] = "s\250\271\201\060\211\070\224\071\375\067!";
144
145 ret = mbstoc32s (input, original, 10);
146 ASSERT (ret == 5);
147
148 for (n = 0; n < 15; n++)
149 {
150 ret = c32stombs (NULL, input, n);
151 ASSERT (ret == 12);
152
153 ret = c32stombs (buf, input, n);
154 ASSERT (ret == (n < 1 ? n :
155 n < 3 ? 1 :
156 n < 7 ? 3 :
157 n < 11 ? 7 :
158 n <= 12 ? n : 12));
159 ASSERT (memcmp (buf, original, ret) == 0);
160 if (n > 12)
161 ASSERT (buf[ret] == '\0');
162 ASSERT (buf[ret + (n > 12) + 0] == '_');
163 ASSERT (buf[ret + (n > 12) + 1] == '_');
164 ASSERT (buf[ret + (n > 12) + 2] == '_');
165 }
166 }
167 break;
168
169 default:
170 return 1;
171 }
172
173 return 0;
174 }
175
176 return 1;
177 }