Update.
[platform/upstream/glibc.git] / localedata / tst-digits.c
1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@gnu.org>, 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 <ctype.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <wctype.h>
24 #include <sys/types.h>
25
26
27 #define ZERO  "\xe2\x82\x80"
28 #define ONE   "\xe2\x82\x81"
29 #define TWO   "\xe2\x82\x82"
30 #define THREE "\xe2\x82\x83"
31 #define FOUR  "\xe2\x82\x84"
32 #define FIVE  "\xe2\x82\x85"
33 #define SIX   "\xe2\x82\x86"
34 #define SEVEN "\xe2\x82\x87"
35 #define EIGHT "\xe2\x82\x88"
36 #define NINE  "\xe2\x82\x89"
37
38 static struct printf_int_test
39 {
40   int n;
41   const char *format;
42   const char *expected;
43 } printf_int_tests[] =
44 {
45   {       0, "%I'10d", "       " ZERO },
46   {       1, "%I'10d", "       " ONE },
47   {       2, "%I'10d", "       " TWO },
48   {       3, "%I'10d", "       " THREE },
49   {       4, "%I'10d", "       " FOUR },
50   {       5, "%I'10d", "       " FIVE },
51   {       6, "%I'10d", "       " SIX },
52   {       7, "%I'10d", "       " SEVEN },
53   {       8, "%I'10d", "       " EIGHT },
54   {       9, "%I'10d", "       " NINE },
55   {      11, "%I'10d", "    " ONE ONE },
56   {      12, "%I'10d", "    " ONE TWO },
57   {     123, "%I10d",  " " ONE TWO THREE },
58   {     123, "%I'10d", " " ONE TWO THREE },
59   {    1234, "%I10d",  ONE TWO THREE FOUR },
60   {    1234, "%I'10d", ONE "," TWO THREE FOUR },
61   {   12345, "%I'10d", ONE TWO "," THREE FOUR FIVE },
62   {  123456, "%I'10d", ONE TWO THREE "," FOUR FIVE SIX },
63   { 1234567, "%I'10d", ONE "," TWO THREE FOUR "," FIVE SIX SEVEN }
64 };
65
66
67
68 int
69 main (void)
70 {
71   int cnt;
72   int failures = 0;
73   int status;
74
75   if (setlocale (LC_ALL, "test7") == NULL)
76     {
77       puts ("cannot set locale `test7'");
78       exit (1);
79     }
80
81   /* First: printf tests.  */
82   for (cnt = 0; cnt < sizeof (printf_int_tests) / sizeof (printf_int_tests[0]);
83        ++cnt)
84     {
85       char buf[100];
86       ssize_t n;
87
88       n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
89                     printf_int_tests[cnt].n);
90
91       if (n != strlen (printf_int_tests[cnt].expected)
92           || strcmp (buf, printf_int_tests[cnt].expected) != 0)
93         {
94           printf ("%3d: got \"%s\", expected \"%s\"\n",
95                   cnt, buf, printf_int_tests[cnt].expected);
96           ++failures;
97         }
98     }
99
100   printf ("\n%d failures in printf tests\n", failures);
101   status = failures != 0;
102
103   /* ctype tests.  This makes sure that the multibyte chracter digit
104      representations are not handle in this table.  */
105   for (cnt = 0; cnt < 256; ++cnt)
106     if (cnt >= '0' && cnt <= '9')
107       {
108         if (! isdigit (cnt))
109           {
110             printf ("isdigit ('%c') == 0\n", cnt);
111             ++failures;
112           }
113       }
114     else
115       {
116         if (isdigit (cnt))
117           {
118             printf ("isdigit (%d) != 0\n", cnt);
119             ++failures;
120           }
121       }
122
123   printf ("\n%d failures in ctype tests\n", failures);
124   status = failures != 0;
125
126   /* wctype tests.  This makes sure the second set of digits is also
127      recorded.  */
128   for (cnt = 0; cnt < 256; ++cnt)
129     if (cnt >= '0' && cnt <= '9')
130       {
131         if (! iswdigit (cnt))
132           {
133             printf ("iswdigit (L'%c') == 0\n", cnt);
134             ++failures;
135           }
136       }
137     else
138       {
139         if (iswdigit (cnt))
140           {
141             printf ("iswdigit (%d) != 0\n", cnt);
142             ++failures;
143           }
144       }
145
146   for (cnt = 0x2070; cnt < 0x2090; ++cnt)
147     if (cnt >= 0x2080 && cnt <= 0x2089)
148       {
149         if (! iswdigit (cnt))
150           {
151             printf ("iswdigit (U%04X) == 0\n", cnt);
152             ++failures;
153           }
154       }
155     else
156       {
157         if (iswdigit (cnt))
158           {
159             printf ("iswdigit (U%04X) != 0\n", cnt);
160             ++failures;
161           }
162       }
163
164   printf ("\n%d failures in wctype tests\n", failures);
165   status = failures != 0;
166
167   return status;
168 }