1 /* Copyright (C) 2000-2016 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
28 #include <sys/types.h>
31 #define ZERO "\xe2\x82\x80"
32 #define ONE "\xe2\x82\x81"
33 #define TWO "\xe2\x82\x82"
34 #define THREE "\xe2\x82\x83"
35 #define FOUR "\xe2\x82\x84"
36 #define FIVE "\xe2\x82\x85"
37 #define SIX "\xe2\x82\x86"
38 #define SEVEN "\xe2\x82\x87"
39 #define EIGHT "\xe2\x82\x88"
40 #define NINE "\xe2\x82\x89"
42 static struct printf_int_test
47 } printf_int_tests
[] =
49 { 0, "%I'10d", " " ZERO
},
50 { 1, "%I'10d", " " ONE
},
51 { 2, "%I'10d", " " TWO
},
52 { 3, "%I'10d", " " THREE
},
53 { 4, "%I'10d", " " FOUR
},
54 { 5, "%I'10d", " " FIVE
},
55 { 6, "%I'10d", " " SIX
},
56 { 7, "%I'10d", " " SEVEN
},
57 { 8, "%I'10d", " " EIGHT
},
58 { 9, "%I'10d", " " NINE
},
59 { 11, "%I'10d", " " ONE ONE
},
60 { 12, "%I'10d", " " ONE TWO
},
61 { 123, "%I10d", " " ONE TWO THREE
},
62 { 123, "%I'10d", " " ONE TWO THREE
},
63 { 1234, "%I10d", ONE TWO THREE FOUR
},
64 { 1234, "%I'10d", ONE
"," TWO THREE FOUR
},
65 { 12345, "%I'10d", ONE TWO
"," THREE FOUR FIVE
},
66 { 123456, "%I'10d", ONE TWO THREE
"," FOUR FIVE SIX
},
67 { 1234567, "%I'10d", ONE
"," TWO THREE FOUR
"," FIVE SIX SEVEN
}
69 #define nprintf_int_tests \
70 (sizeof (printf_int_tests) / sizeof (printf_int_tests[0]))
72 #define WZERO L"\x2080"
73 #define WONE L"\x2081"
74 #define WTWO L"\x2082"
75 #define WTHREE L"\x2083"
76 #define WFOUR L"\x2084"
77 #define WFIVE L"\x2085"
78 #define WSIX L"\x2086"
79 #define WSEVEN L"\x2087"
80 #define WEIGHT L"\x2088"
81 #define WNINE L"\x2089"
83 static struct wprintf_int_test
86 const wchar_t *format
;
87 const wchar_t *expected
;
88 } wprintf_int_tests
[] =
90 { 0, L
"%I'10d", L
" " WZERO
},
91 { 1, L
"%I'10d", L
" " WONE
},
92 { 2, L
"%I'10d", L
" " WTWO
},
93 { 3, L
"%I'10d", L
" " WTHREE
},
94 { 4, L
"%I'10d", L
" " WFOUR
},
95 { 5, L
"%I'10d", L
" " WFIVE
},
96 { 6, L
"%I'10d", L
" " WSIX
},
97 { 7, L
"%I'10d", L
" " WSEVEN
},
98 { 8, L
"%I'10d", L
" " WEIGHT
},
99 { 9, L
"%I'10d", L
" " WNINE
},
100 { 11, L
"%I'10d", L
" " WONE WONE
},
101 { 12, L
"%I'10d", L
" " WONE WTWO
},
102 { 123, L
"%I10d", L
" " WONE WTWO WTHREE
},
103 { 123, L
"%I'10d", L
" " WONE WTWO WTHREE
},
104 { 1234, L
"%I10d", L
" " WONE WTWO WTHREE WFOUR
},
105 { 1234, L
"%I'10d", L
" " WONE L
"," WTWO WTHREE WFOUR
},
106 { 12345, L
"%I'10d", L
" " WONE WTWO L
"," WTHREE WFOUR WFIVE
},
107 { 123456, L
"%I'10d", L
" " WONE WTWO WTHREE L
"," WFOUR WFIVE WSIX
},
108 { 1234567, L
"%I'10d", L
" " WONE L
"," WTWO WTHREE WFOUR L
"," WFIVE WSIX WSEVEN
}
110 #define nwprintf_int_tests \
111 (sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]))
121 if (setlocale (LC_ALL
, "test7") == NULL
)
123 puts ("cannot set locale `test7'");
126 printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET
));
128 /* First: printf tests. */
130 for (cnt
= 0; cnt
< (int) nprintf_int_tests
; ++cnt
)
135 n
= snprintf (buf
, sizeof buf
, printf_int_tests
[cnt
].format
,
136 printf_int_tests
[cnt
].n
);
138 printf ("%3d: got \"%s\", expected \"%s\"",
139 cnt
, buf
, printf_int_tests
[cnt
].expected
);
141 if (n
!= (ssize_t
) strlen (printf_int_tests
[cnt
].expected
)
142 || strcmp (buf
, printf_int_tests
[cnt
].expected
) != 0)
151 printf ("%d failures in printf tests\n", failures
);
152 status
= failures
!= 0;
156 for (cnt
= 0; cnt
< (int) nwprintf_int_tests
; ++cnt
)
161 n
= swprintf (buf
, sizeof buf
/ sizeof (buf
[0]),
162 wprintf_int_tests
[cnt
].format
,
163 wprintf_int_tests
[cnt
].n
);
165 printf ("%3d: got \"%ls\", expected \"%ls\"",
166 cnt
, buf
, wprintf_int_tests
[cnt
].expected
);
168 if (n
!= (ssize_t
) wcslen (wprintf_int_tests
[cnt
].expected
)
169 || wcscmp (buf
, wprintf_int_tests
[cnt
].expected
) != 0)
178 printf ("%d failures in wprintf tests\n", failures
);
179 status
= failures
!= 0;
181 /* ctype tests. This makes sure that the multibyte character digit
182 representations are not handle in this table. */
184 for (cnt
= 0; cnt
< 256; ++cnt
)
185 if (cnt
>= '0' && cnt
<= '9')
189 printf ("isdigit ('%c') == 0\n", cnt
);
197 printf ("isdigit (%d) != 0\n", cnt
);
202 printf ("%d failures in ctype tests\n", failures
);
203 status
= failures
!= 0;
205 /* wctype tests. This makes sure the second set of digits is also
208 for (cnt
= 0; cnt
< 256; ++cnt
)
209 if (cnt
>= '0' && cnt
<= '9')
211 if (! iswdigit (cnt
))
213 printf ("iswdigit (L'%c') == 0\n", cnt
);
221 printf ("iswdigit (%d) != 0\n", cnt
);
226 for (cnt
= 0x2070; cnt
< 0x2090; ++cnt
)
227 if (cnt
>= 0x2080 && cnt
<= 0x2089)
229 if (! iswdigit (cnt
))
231 printf ("iswdigit (U%04X) == 0\n", cnt
);
239 printf ("iswdigit (U%04X) != 0\n", cnt
);
244 printf ("%d failures in wctype tests\n", failures
);
245 status
= failures
!= 0;
250 #define TEST_FUNCTION do_test ()
251 #include "../test-skeleton.c"