]> git.ipfire.org Git - thirdparty/glibc.git/blame - wcsmbs/tst-mbrtowc.c
Update.
[thirdparty/glibc.git] / wcsmbs / tst-mbrtowc.c
CommitLineData
bb2fc850
UD
1/* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <locale.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <wchar.h>
25
26
27static int check_ascii (const char *locname);
28
29
30int
31main (void)
32{
33 int result = 0;
34
35 /* Check mapping of ASCII range for some character sets which have
36 ASCII as a subset. For those the wide char generated must have
37 the same value. */
38 setlocale (LC_ALL, "C");
39 result |= check_ascii (setlocale (LC_ALL, NULL));
40
41 setlocale (LC_ALL, "de_DE.UTF-8");
42 result |= check_ascii (setlocale (LC_ALL, NULL));
43
44 setlocale (LC_ALL, "ja_JP.EUC-JP");
45 result |= check_ascii (setlocale (LC_ALL, NULL));
46
47 return result;
48}
49
50
51static int
52check_ascii (const char *locname)
53{
54 int c;
55 int res = 0;
56
57 printf ("Testing locale \"%s\":\n", locname);
58
59 for (c = 0; c <= 127; ++c)
60 {
61 char buf[MB_CUR_MAX];
62 wchar_t wc = 0xffffffff;
63 mbstate_t s;
64 size_t n;
65 int i;
66
67 for (i = 0; i < MB_CUR_MAX; ++i)
68 buf[i] = c + i;
69
70 memset (&s, '\0', sizeof (s));
71
72 n = mbrtowc (&wc, buf, MB_CUR_MAX, &s);
73 if (n == (size_t) -1)
74 {
75 printf ("%s: '\\x%x': encoding error\n", locname, c);
76 ++res;
77 }
78 else if (n == (size_t) -2)
79 {
80 printf ("%s: '\\x%x': incomplete character\n", locname, c);
81 ++res;
82 }
83 else if (n == 0 && c != 0)
84 {
85 printf ("%s: '\\x%x': 0 returned\n", locname, c);
86 ++res;
87 }
88 else if (n != 0 && c == 0)
89 {
90 printf ("%s: '\\x%x': not 0 returned\n", locname, c);
91 ++res;
92 }
93 else if (c != 0 && n != 1)
94 {
95 printf ("%s: '\\x%x': not 1 returned\n", locname, c);
96 ++res;
97 }
98 else if (wc != (wchar_t) c)
99 {
100 printf ("%s: '\\x%x': wc != L'\\x%x'\n", locname, c, c);
101 ++res;
102 }
103 }
104
105 printf (res == 1 ? "%d error\n" : "%d errors\n", res);
106
107 return res != 0;
108}