1acbd8998SOliver Tappe/* Test of conversion of multibyte character to wide character.
2acbd8998SOliver Tappe   Copyright (C) 2008-2011 Free Software Foundation, Inc.
3acbd8998SOliver Tappe
4acbd8998SOliver Tappe   This program is free software: you can redistribute it and/or modify
5acbd8998SOliver Tappe   it under the terms of the GNU General Public License as published by
6acbd8998SOliver Tappe   the Free Software Foundation; either version 3 of the License, or
7acbd8998SOliver Tappe   (at your option) any later version.
8acbd8998SOliver Tappe
9acbd8998SOliver Tappe   This program is distributed in the hope that it will be useful,
10acbd8998SOliver Tappe   but WITHOUT ANY WARRANTY; without even the implied warranty of
12acbd8998SOliver Tappe   GNU General Public License for more details.
13acbd8998SOliver Tappe
14acbd8998SOliver Tappe   You should have received a copy of the GNU General Public License
15acbd8998SOliver Tappe   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16acbd8998SOliver Tappe
17acbd8998SOliver Tappe/* Written by Bruno Haible <bruno@clisp.org>, 2008.  */
18acbd8998SOliver Tappe
19acbd8998SOliver Tappe#undef NDEBUG
20acbd8998SOliver Tappe#include <assert.h>
21acbd8998SOliver Tappe#include <locale.h>
22acbd8998SOliver Tappe#include <stdio.h>
23acbd8998SOliver Tappe#include <string.h>
24acbd8998SOliver Tappe#include <wchar.h>
25acbd8998SOliver Tappe
26acbd8998SOliver Tappe#include <Debug.h>
27acbd8998SOliver Tappe
28acbd8998SOliver Tappeint
29acbd8998SOliver Tappemain (int argc, char *argv[])
30acbd8998SOliver Tappe{
31acbd8998SOliver Tappe  mbstate_t state;
32acbd8998SOliver Tappe  wchar_t wc;
33acbd8998SOliver Tappe  size_t ret;
34acbd8998SOliver Tappe  int i;
35acbd8998SOliver Tappe
36acbd8998SOliver Tappe  /* configure should already have checked that the locale is supported.  */
37acbd8998SOliver Tappe  if (setlocale (LC_ALL, "") == NULL) {
38acbd8998SOliver Tappe	fprintf(stderr, "unable to set standard locale\n");
39acbd8998SOliver Tappe    return 1;
40acbd8998SOliver Tappe  }
41acbd8998SOliver Tappe
42acbd8998SOliver Tappe  /* Test zero-length input.  */
43acbd8998SOliver Tappe  printf("zero-length input ...\n");
44acbd8998SOliver Tappe  {
45acbd8998SOliver Tappe    memset (&state, '\0', sizeof (mbstate_t));
46acbd8998SOliver Tappe    wc = (wchar_t) 0xBADFACE;
47acbd8998SOliver Tappe    ret = mbrtowc (&wc, "x", 0, &state);
48acbd8998SOliver Tappe    /* gnulib's implementation returns (size_t)(-2).
49acbd8998SOliver Tappe       The AIX 5.1 implementation returns (size_t)(-1).
50acbd8998SOliver Tappe       glibc's implementation returns 0.  */
51acbd8998SOliver Tappe    assert (ret == (size_t)(-2) || ret == (size_t)(-1) || ret == 0);
52acbd8998SOliver Tappe    assert (mbsinit (&state));
53acbd8998SOliver Tappe  }
54acbd8998SOliver Tappe
55acbd8998SOliver Tappe  /* Test NUL byte input.  */
56acbd8998SOliver Tappe  printf("NUL byte input ...\n");
57acbd8998SOliver Tappe  {
58acbd8998SOliver Tappe    memset (&state, '\0', sizeof (mbstate_t));
59acbd8998SOliver Tappe    wc = (wchar_t) 0xBADFACE;
60acbd8998SOliver Tappe    ret = mbrtowc (&wc, "", 1, &state);
61acbd8998SOliver Tappe    assert (ret == 0);
62acbd8998SOliver Tappe    assert (wc == 0);
63acbd8998SOliver Tappe    assert (mbsinit (&state));
64acbd8998SOliver Tappe    ret = mbrtowc (NULL, "", 1, &state);
65acbd8998SOliver Tappe    assert (ret == 0);
66acbd8998SOliver Tappe    assert (mbsinit (&state));
67acbd8998SOliver Tappe  }
68acbd8998SOliver Tappe
69acbd8998SOliver Tappe  /* Test single-byte input.  */
70acbd8998SOliver Tappe  printf("single-byte input ...\n");
71acbd8998SOliver Tappe  {
72acbd8998SOliver Tappe    char buf[1];
73acbd8998SOliver Tappe    int c;
74acbd8998SOliver Tappe
75acbd8998SOliver Tappe    memset (&state, '\0', sizeof (mbstate_t));
76acbd8998SOliver Tappe    for (c = 0; c < 0x100; c++)
77acbd8998SOliver Tappe      switch (c)
78acbd8998SOliver Tappe        {
79acbd8998SOliver Tappe        case '\t': case '\v': case '\f':
80acbd8998SOliver Tappe        case ' ': case '!': case '"': case '#': case '%':
81acbd8998SOliver Tappe        case '&': case '\'': case '(': case ')': case '*':
82acbd8998SOliver Tappe        case '+': case ',': case '-': case '.': case '/':
83acbd8998SOliver Tappe        case '0': case '1': case '2': case '3': case '4':
84acbd8998SOliver Tappe        case '5': case '6': case '7': case '8': case '9':
85acbd8998SOliver Tappe        case ':': case ';': case '<': case '=': case '>':
86acbd8998SOliver Tappe        case '?':
87acbd8998SOliver Tappe        case 'A': case 'B': case 'C': case 'D': case 'E':
88acbd8998SOliver Tappe        case 'F': case 'G': case 'H': case 'I': case 'J':
89acbd8998SOliver Tappe        case 'K': case 'L': case 'M': case 'N': case 'O':
90acbd8998SOliver Tappe        case 'P': case 'Q': case 'R': case 'S': case 'T':
91acbd8998SOliver Tappe        case 'U': case 'V': case 'W': case 'X': case 'Y':
92acbd8998SOliver Tappe        case 'Z':
93acbd8998SOliver Tappe        case '[': case '\\': case ']': case '^': case '_':
94acbd8998SOliver Tappe        case 'a': case 'b': case 'c': case 'd': case 'e':
95acbd8998SOliver Tappe        case 'f': case 'g': case 'h': case 'i': case 'j':
96acbd8998SOliver Tappe        case 'k': case 'l': case 'm': case 'n': case 'o':
97acbd8998SOliver Tappe        case 'p': case 'q': case 'r': case 's': case 't':
98acbd8998SOliver Tappe        case 'u': case 'v': case 'w': case 'x': case 'y':
99acbd8998SOliver Tappe        case 'z': case '{': case '|': case '}': case '~':
100acbd8998SOliver Tappe          /* c is in the ISO C "basic character set".  */
101acbd8998SOliver Tappe          buf[0] = c;
102acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
103acbd8998SOliver Tappe          ret = mbrtowc (&wc, buf, 1, &state);
104acbd8998SOliver Tappe          assert (ret == 1);
105acbd8998SOliver Tappe          assert (wc == c);
106acbd8998SOliver Tappe          assert (mbsinit (&state));
107acbd8998SOliver Tappe          ret = mbrtowc (NULL, buf, 1, &state);
108acbd8998SOliver Tappe          assert (ret == 1);
109acbd8998SOliver Tappe          assert (mbsinit (&state));
110acbd8998SOliver Tappe          break;
111acbd8998SOliver Tappe        }
112acbd8998SOliver Tappe  }
113acbd8998SOliver Tappe
114acbd8998SOliver Tappe  /* Test special calling convention, passing a NULL pointer.  */
115acbd8998SOliver Tappe  printf("special calling convention, passing NULL ...\n");
116acbd8998SOliver Tappe  {
117acbd8998SOliver Tappe    memset (&state, '\0', sizeof (mbstate_t));
118acbd8998SOliver Tappe    wc = (wchar_t) 0xBADFACE;
119acbd8998SOliver Tappe    ret = mbrtowc (&wc, NULL, 5, &state);
120acbd8998SOliver Tappe    assert (ret == 0);
121acbd8998SOliver Tappe    assert (wc == (wchar_t) 0xBADFACE);
122acbd8998SOliver Tappe    assert (mbsinit (&state));
123acbd8998SOliver Tappe  }
124acbd8998SOliver Tappe
125acbd8998SOliver Tappe  for (i = '1'; i <= '4'; ++i) {
126acbd8998SOliver Tappe    switch (i)
127acbd8998SOliver Tappe      {
128acbd8998SOliver Tappe      case '1':
129acbd8998SOliver Tappe        /* Locale encoding is ISO-8859-1 or ISO-8859-15.  */
130acbd8998SOliver Tappe    	printf("ISO8859-1 ...\n");
131acbd8998SOliver Tappe        {
132acbd8998SOliver Tappe          char input[] = "B\374\337er"; /* "B����er" */
133acbd8998SOliver Tappe          memset (&state, '\0', sizeof (mbstate_t));
134acbd8998SOliver Tappe
135acbd8998SOliver Tappe       	  if (setlocale (LC_ALL, "en_US.ISO8859-1") == NULL) {
136acbd8998SOliver Tappe       		  fprintf(stderr, "unable to set ISO8859-1 locale, skipping\n");
137acbd8998SOliver Tappe       		  break;
138acbd8998SOliver Tappe       	  }
139acbd8998SOliver Tappe
140acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
141acbd8998SOliver Tappe          ret = mbrtowc (&wc, input, 1, &state);
142acbd8998SOliver Tappe          assert (ret == 1);
143acbd8998SOliver Tappe          assert (wc == 'B');
144acbd8998SOliver Tappe          assert (mbsinit (&state));
145acbd8998SOliver Tappe          input[0] = '\0';
146acbd8998SOliver Tappe
147acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
148acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 1, 1, &state);
149acbd8998SOliver Tappe          assert (ret == 1);
150acbd8998SOliver Tappe          assert (wctob (wc) == (unsigned char) '\374');
151acbd8998SOliver Tappe          assert (mbsinit (&state));
152acbd8998SOliver Tappe          input[1] = '\0';
153acbd8998SOliver Tappe
154acbd8998SOliver Tappe          /* Test support of NULL first argument.  */
155acbd8998SOliver Tappe          ret = mbrtowc (NULL, input + 2, 3, &state);
156acbd8998SOliver Tappe          assert (ret == 1);
157acbd8998SOliver Tappe          assert (mbsinit (&state));
158acbd8998SOliver Tappe
159acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
160acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 2, 3, &state);
161acbd8998SOliver Tappe          assert (ret == 1);
162acbd8998SOliver Tappe          assert (wctob (wc) == (unsigned char) '\337');
163acbd8998SOliver Tappe          assert (mbsinit (&state));
164acbd8998SOliver Tappe          input[2] = '\0';
165acbd8998SOliver Tappe
166acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
167acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 3, 2, &state);
168acbd8998SOliver Tappe          assert (ret == 1);
169acbd8998SOliver Tappe          assert (wc == 'e');
170acbd8998SOliver Tappe          assert (mbsinit (&state));
171acbd8998SOliver Tappe          input[3] = '\0';
172acbd8998SOliver Tappe
173acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
174acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 4, 1, &state);
175acbd8998SOliver Tappe          assert (ret == 1);
176acbd8998SOliver Tappe          assert (wc == 'r');
177acbd8998SOliver Tappe          assert (mbsinit (&state));
178acbd8998SOliver Tappe        }
179acbd8998SOliver Tappe        break;
180acbd8998SOliver Tappe
181acbd8998SOliver Tappe      case '2':
182acbd8998SOliver Tappe        /* Locale encoding is UTF-8.  */
183acbd8998SOliver Tappe      	printf("UTF-8 ...\n");
184acbd8998SOliver Tappe        {
185acbd8998SOliver Tappe          char input[] = "B\303\274\303\237er"; /* "B����er" */
186acbd8998SOliver Tappe          memset (&state, '\0', sizeof (mbstate_t));
187acbd8998SOliver Tappe
188acbd8998SOliver Tappe		  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL) {
189acbd8998SOliver Tappe			  fprintf(stderr, "unable to set UTF-8 locale, skipping\n");
190acbd8998SOliver Tappe			  break;
191acbd8998SOliver Tappe		  }
192acbd8998SOliver Tappe
193acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
194acbd8998SOliver Tappe          ret = mbrtowc (&wc, input, 1, &state);
195acbd8998SOliver Tappe          assert (ret == 1);
196acbd8998SOliver Tappe          assert (wc == 'B');
197acbd8998SOliver Tappe          assert (mbsinit (&state));
198acbd8998SOliver Tappe          input[0] = '\0';
199acbd8998SOliver Tappe
200acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
201acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 1, 1, &state);
202acbd8998SOliver Tappe          assert (ret == (size_t)(-2));
203acbd8998SOliver Tappe          assert (wc == (wchar_t) 0xBADFACE);
204acbd8998SOliver Tappe          assert (!mbsinit (&state));
205acbd8998SOliver Tappe          input[1] = '\0';
206acbd8998SOliver Tappe
207acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
208acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 2, 5, &state);
209acbd8998SOliver Tappe          assert (ret == 1);
210acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
211acbd8998SOliver Tappe          assert (mbsinit (&state));
212acbd8998SOliver Tappe          input[2] = '\0';
213acbd8998SOliver Tappe
214acbd8998SOliver Tappe          /* Test support of NULL first argument.  */
215acbd8998SOliver Tappe          ret = mbrtowc (NULL, input + 3, 4, &state);
216acbd8998SOliver Tappe          assert (ret == 2);
217acbd8998SOliver Tappe          assert (mbsinit (&state));
218acbd8998SOliver Tappe
219acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
220acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 3, 4, &state);
221acbd8998SOliver Tappe          assert (ret == 2);
222acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
223acbd8998SOliver Tappe          assert (mbsinit (&state));
224acbd8998SOliver Tappe          input[3] = '\0';
225acbd8998SOliver Tappe          input[4] = '\0';
226acbd8998SOliver Tappe
227acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
228acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 5, 2, &state);
229acbd8998SOliver Tappe          assert (ret == 1);
230acbd8998SOliver Tappe          assert (wc == 'e');
231acbd8998SOliver Tappe          assert (mbsinit (&state));
232acbd8998SOliver Tappe          input[5] = '\0';
233acbd8998SOliver Tappe
234acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
235acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 6, 1, &state);
236acbd8998SOliver Tappe          assert (ret == 1);
237acbd8998SOliver Tappe          assert (wc == 'r');
238acbd8998SOliver Tappe          assert (mbsinit (&state));
2398726c67fSOliver Tappe
2408726c67fSOliver Tappe          /* reproduce a valid use case from readline (as used in our bash): */
2418726c67fSOliver Tappe          {
2428726c67fSOliver Tappe	        char tooShort[] = "\303";
2438726c67fSOliver Tappe	        char ok[] = "\303\274";
2448726c67fSOliver Tappe        	/* make a backup of the state */
2458726c67fSOliver Tappe        	mbstate_t stateBackup = state;
2468726c67fSOliver Tappe        	/* try with a source that's too short */
2478726c67fSOliver Tappe            ret = mbrtowc (&wc, tooShort, 1, &state);
2488726c67fSOliver Tappe            assert (ret == (size_t)-2);
2498726c67fSOliver Tappe            /* restore the state from the backup */
2508726c67fSOliver Tappe            state = stateBackup;
2518726c67fSOliver Tappe			/* retry with enough source */
2528726c67fSOliver Tappe            ret = mbrtowc (&wc, ok, 2, &state);
2538726c67fSOliver Tappe            assert (ret == 2);
2548726c67fSOliver Tappe          }
255acbd8998SOliver Tappe        }
256acbd8998SOliver Tappe        break;
257acbd8998SOliver Tappe
258acbd8998SOliver Tappe      case '3':
259acbd8998SOliver Tappe        /* Locale encoding is EUC-JP.  */
260acbd8998SOliver Tappe       	printf("EUC-JP ...\n");
261acbd8998SOliver Tappe        {
262acbd8998SOliver Tappe          char input[] = "<\306\374\313\334\270\354>"; /* "<���������>" */
263acbd8998SOliver Tappe          memset (&state, '\0', sizeof (mbstate_t));
264acbd8998SOliver Tappe
265acbd8998SOliver Tappe		  if (setlocale (LC_ALL, "en_US.EUC-JP") == NULL) {
266acbd8998SOliver Tappe			  fprintf(stderr, "unable to set EUC-JP locale, skipping\n");
267acbd8998SOliver Tappe			  break;
268acbd8998SOliver Tappe		  }
269acbd8998SOliver Tappe
270acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
271acbd8998SOliver Tappe          ret = mbrtowc (&wc, input, 1, &state);
272acbd8998SOliver Tappe          assert (ret == 1);
273acbd8998SOliver Tappe          assert (wc == '<');
274acbd8998SOliver Tappe          assert (mbsinit (&state));
275acbd8998SOliver Tappe          input[0] = '\0';
276acbd8998SOliver Tappe
277acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
278acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 1, 2, &state);
279acbd8998SOliver Tappe          assert (ret == 2);
280acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
281acbd8998SOliver Tappe          assert (mbsinit (&state));
282acbd8998SOliver Tappe          input[1] = '\0';
283acbd8998SOliver Tappe          input[2] = '\0';
284acbd8998SOliver Tappe
285acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
286acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 3, 1, &state);
287acbd8998SOliver Tappe          assert (ret == (size_t)(-2));
288acbd8998SOliver Tappe          assert (wc == (wchar_t) 0xBADFACE);
289acbd8998SOliver Tappe          assert (!mbsinit (&state));
290acbd8998SOliver Tappe          input[3] = '\0';
291acbd8998SOliver Tappe
292acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
293acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 4, 4, &state);
294acbd8998SOliver Tappe          assert (ret == 1);
295acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
296acbd8998SOliver Tappe          assert (mbsinit (&state));
297acbd8998SOliver Tappe          input[4] = '\0';
298acbd8998SOliver Tappe
299acbd8998SOliver Tappe          /* Test support of NULL first argument.  */
300acbd8998SOliver Tappe          ret = mbrtowc (NULL, input + 5, 3, &state);
301acbd8998SOliver Tappe          assert (ret == 2);
302acbd8998SOliver Tappe          assert (mbsinit (&state));
303acbd8998SOliver Tappe
304acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
305acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 5, 3, &state);
306acbd8998SOliver Tappe          assert (ret == 2);
307acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
308acbd8998SOliver Tappe          assert (mbsinit (&state));
309acbd8998SOliver Tappe          input[5] = '\0';
310acbd8998SOliver Tappe          input[6] = '\0';
311acbd8998SOliver Tappe
312acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
313acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 7, 1, &state);
314acbd8998SOliver Tappe          assert (ret == 1);
315acbd8998SOliver Tappe          assert (wc == '>');
316acbd8998SOliver Tappe          assert (mbsinit (&state));
317acbd8998SOliver Tappe        }
318acbd8998SOliver Tappe        break;
319acbd8998SOliver Tappe
320acbd8998SOliver Tappe      case '4':
321acbd8998SOliver Tappe        /* Locale encoding is GB18030.  */
322acbd8998SOliver Tappe       	printf("GB18030 ...\n");
323acbd8998SOliver Tappe        {
324acbd8998SOliver Tappe          char input[] = "B\250\271\201\060\211\070er"; /* "B����er" */
325acbd8998SOliver Tappe          memset (&state, '\0', sizeof (mbstate_t));
326acbd8998SOliver Tappe
327acbd8998SOliver Tappe		  if (setlocale (LC_ALL, "en_US.GB18030") == NULL) {
328acbd8998SOliver Tappe			  fprintf(stderr, "unable to set GB18030 locale, skipping\n");
329acbd8998SOliver Tappe			  break;
330acbd8998SOliver Tappe		  }
331acbd8998SOliver Tappe
332acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
333acbd8998SOliver Tappe          ret = mbrtowc (&wc, input, 1, &state);
334acbd8998SOliver Tappe          assert (ret == 1);
335acbd8998SOliver Tappe          assert (wc == 'B');
336acbd8998SOliver Tappe          assert (mbsinit (&state));
337acbd8998SOliver Tappe          input[0] = '\0';
338acbd8998SOliver Tappe
339acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
340acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 1, 1, &state);
341acbd8998SOliver Tappe          assert (ret == (size_t)(-2));
342acbd8998SOliver Tappe          assert (wc == (wchar_t) 0xBADFACE);
343acbd8998SOliver Tappe          assert (!mbsinit (&state));
344acbd8998SOliver Tappe          input[1] = '\0';
345acbd8998SOliver Tappe
346acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
347acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 2, 7, &state);
348acbd8998SOliver Tappe          assert (ret == 1);
349acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
350acbd8998SOliver Tappe          assert (mbsinit (&state));
351acbd8998SOliver Tappe          input[2] = '\0';
352acbd8998SOliver Tappe
353acbd8998SOliver Tappe          /* Test support of NULL first argument.  */
354acbd8998SOliver Tappe          ret = mbrtowc (NULL, input + 3, 6, &state);
355acbd8998SOliver Tappe          assert (ret == 4);
356acbd8998SOliver Tappe          assert (mbsinit (&state));
357acbd8998SOliver Tappe
358acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
359acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 3, 6, &state);
360acbd8998SOliver Tappe          assert (ret == 4);
361acbd8998SOliver Tappe          assert (wctob (wc) == EOF);
362acbd8998SOliver Tappe          assert (mbsinit (&state));
363acbd8998SOliver Tappe          input[3] = '\0';
364acbd8998SOliver Tappe          input[4] = '\0';
365acbd8998SOliver Tappe          input[5] = '\0';
366acbd8998SOliver Tappe          input[6] = '\0';
367acbd8998SOliver Tappe
368acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
369acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 7, 2, &state);
370acbd8998SOliver Tappe          assert (ret == 1);
371acbd8998SOliver Tappe          assert (wc == 'e');
372acbd8998SOliver Tappe          assert (mbsinit (&state));
373acbd8998SOliver Tappe          input[5] = '\0';
374acbd8998SOliver Tappe
375acbd8998SOliver Tappe          wc = (wchar_t) 0xBADFACE;
376acbd8998SOliver Tappe          ret = mbrtowc (&wc, input + 8, 1, &state);
377acbd8998SOliver Tappe          assert (ret == 1);
378acbd8998SOliver Tappe          assert (wc == 'r');
379acbd8998SOliver Tappe          assert (mbsinit (&state));
380acbd8998SOliver Tappe        }
381acbd8998SOliver Tappe        break;
382acbd8998SOliver Tappe      }
383acbd8998SOliver Tappe  }
384acbd8998SOliver Tappe
385acbd8998SOliver Tappe  return 0;
386acbd8998SOliver Tappe}