]> git.ipfire.org Git - thirdparty/glibc.git/blame - wcsmbs/tst-wcrtomb.c
Update.
[thirdparty/glibc.git] / wcsmbs / tst-wcrtomb.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 wchar_t wc;
55 int res = 0;
56
57 printf ("Testing locale \"%s\":\n", locname);
58
59 for (wc = 0; wc <= 127; ++wc)
60 {
61 char buf[2 * MB_CUR_MAX];
62 mbstate_t s;
63 size_t n;
64
65 memset (buf, '\xff', sizeof (buf));
66 memset (&s, '\0', sizeof (s));
67
68 n = wcrtomb (buf, wc, &s);
69 if (n == (size_t) -1)
70 {
71 printf ("%s: '\\x%x': encoding error\n", locname, (int) wc);
72 ++res;
73 }
74 else if (n == 0)
75 {
76 printf ("%s: '\\x%x': 0 returned\n", locname, (int) wc);
77 ++res;
78 }
79 else if (n != 1)
80 {
81 printf ("%s: '\\x%x': not 1 returned\n", locname, (int) wc);
82 ++res;
83 }
84 else if (wc != (wchar_t) buf[0])
85 {
86 printf ("%s: L'\\x%x': buf[0] != '\\x%x'\n", locname, (int) wc,
87 (int) wc);
88 ++res;
89 }
90 }
91
92 printf (res == 1 ? "%d error\n" : "%d errors\n", res);
93
94 return res != 0;
95}