[BZ #58]
[glibc.git] / wcsmbs / tst-mbrtowc2.c
blob67d8e29a0f7ebc86b2f453ad9a79880ad9a51341
1 /* Derived from the test case in http://sourceware.org/bugzilla/show_bug.cgi?id=714 */
2 #include <locale.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <wchar.h>
8 static struct
10 const char *chp;
11 size_t nchp;
12 const char *loc;
13 } tests[] =
15 { (const char[]) { 0x8F, 0xA2, 0xAF }, 3, "ja_JP.EUC-JP" },
16 { (const char[]) { 0xD1, 0xA5 }, 2, "ja_JP.EUC-JP" },
17 { (const char[]) { 0x8E, 0xA5 }, 2, "ja_JP.EUC-JP" },
18 { (const char[]) { 0x8E, 0xA2, 0xA1, 0xA1 }, 4, "zh_TW.EUC-TW" },
19 { (const char[]) { 0xA1, 0xA1 }, 2, "zh_TW.EUC-TW" },
20 { (const char[]) { 0xE3, 0x80, 0x80 }, 3, "de_DE.UTF-8" },
21 { (const char[]) { 0xC3, 0xA4 }, 2, "de_DE.UTF-8" }
23 #define ntests (sizeof (tests) / sizeof (tests[0]))
26 static int t (const char *ch, size_t nch, const char *loc);
28 static int
29 do_test (void)
31 int r = 0;
32 for (int i = 0; i < ntests; ++i)
33 r |= t (tests[i].chp, tests[i].nchp, tests[i].loc);
34 return r;
37 static int
38 t (const char *ch, size_t nch, const char *loc)
40 int i;
41 wchar_t wch;
42 wchar_t wch2;
43 mbstate_t mbs;
44 int n = 0;
46 setlocale (LC_ALL, loc);
48 memset (&mbs, '\0', sizeof (mbstate_t));
49 for (i = 0; i < nch; i++)
51 n = mbrtowc (&wch, ch + i, 1, &mbs);
52 if (n >= 0)
53 break;
55 printf ("n = %d, count = %d, wch = %08lX\n", n, i, (unsigned long int) wch);
57 memset (&mbs, '\0', sizeof (mbstate_t));
58 n = mbrtowc (&wch2, ch, nch, &mbs);
59 printf ("n = %d, wch = %08lX\n", n, (unsigned long int) wch2);
61 int ret = n != nch || i + 1 != nch || n != nch || wch != wch2;
62 puts (ret ? "FAIL\n" : "OK\n");
63 return ret;
66 #define TEST_FUNCTION do_test ()
67 #include "../test-skeleton.c"