| 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 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.
|
|---|
| 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 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with the GNU C Library; if not, write to the Free
|
|---|
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 18 | 02111-1307 USA. */
|
|---|
| 19 |
|
|---|
| 20 | #include <ctype.h>
|
|---|
| 21 | #include <langinfo.h>
|
|---|
| 22 | #include <locale.h>
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #include <stdlib.h>
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 | #include <unistd.h>
|
|---|
| 27 | #include <wchar.h>
|
|---|
| 28 | #include <wctype.h>
|
|---|
| 29 | #include <sys/types.h>
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | #define ZERO "\xe2\x82\x80"
|
|---|
| 33 | #define ONE "\xe2\x82\x81"
|
|---|
| 34 | #define TWO "\xe2\x82\x82"
|
|---|
| 35 | #define THREE "\xe2\x82\x83"
|
|---|
| 36 | #define FOUR "\xe2\x82\x84"
|
|---|
| 37 | #define FIVE "\xe2\x82\x85"
|
|---|
| 38 | #define SIX "\xe2\x82\x86"
|
|---|
| 39 | #define SEVEN "\xe2\x82\x87"
|
|---|
| 40 | #define EIGHT "\xe2\x82\x88"
|
|---|
| 41 | #define NINE "\xe2\x82\x89"
|
|---|
| 42 |
|
|---|
| 43 | static struct printf_int_test
|
|---|
| 44 | {
|
|---|
| 45 | int n;
|
|---|
| 46 | const char *format;
|
|---|
| 47 | const char *expected;
|
|---|
| 48 | } printf_int_tests[] =
|
|---|
| 49 | {
|
|---|
| 50 | { 0, "%I'10d", " " ZERO },
|
|---|
| 51 | { 1, "%I'10d", " " ONE },
|
|---|
| 52 | { 2, "%I'10d", " " TWO },
|
|---|
| 53 | { 3, "%I'10d", " " THREE },
|
|---|
| 54 | { 4, "%I'10d", " " FOUR },
|
|---|
| 55 | { 5, "%I'10d", " " FIVE },
|
|---|
| 56 | { 6, "%I'10d", " " SIX },
|
|---|
| 57 | { 7, "%I'10d", " " SEVEN },
|
|---|
| 58 | { 8, "%I'10d", " " EIGHT },
|
|---|
| 59 | { 9, "%I'10d", " " NINE },
|
|---|
| 60 | { 11, "%I'10d", " " ONE ONE },
|
|---|
| 61 | { 12, "%I'10d", " " ONE TWO },
|
|---|
| 62 | { 123, "%I10d", " " ONE TWO THREE },
|
|---|
| 63 | { 123, "%I'10d", " " ONE TWO THREE },
|
|---|
| 64 | { 1234, "%I10d", ONE TWO THREE FOUR },
|
|---|
| 65 | { 1234, "%I'10d", ONE "," TWO THREE FOUR },
|
|---|
| 66 | { 12345, "%I'10d", ONE TWO "," THREE FOUR FIVE },
|
|---|
| 67 | { 123456, "%I'10d", ONE TWO THREE "," FOUR FIVE SIX },
|
|---|
| 68 | { 1234567, "%I'10d", ONE "," TWO THREE FOUR "," FIVE SIX SEVEN }
|
|---|
| 69 | };
|
|---|
| 70 | #define nprintf_int_tests \
|
|---|
| 71 | (sizeof (printf_int_tests) / sizeof (printf_int_tests[0]))
|
|---|
| 72 |
|
|---|
| 73 | #define WZERO L"\x2080"
|
|---|
| 74 | #define WONE L"\x2081"
|
|---|
| 75 | #define WTWO L"\x2082"
|
|---|
| 76 | #define WTHREE L"\x2083"
|
|---|
| 77 | #define WFOUR L"\x2084"
|
|---|
| 78 | #define WFIVE L"\x2085"
|
|---|
| 79 | #define WSIX L"\x2086"
|
|---|
| 80 | #define WSEVEN L"\x2087"
|
|---|
| 81 | #define WEIGHT L"\x2088"
|
|---|
| 82 | #define WNINE L"\x2089"
|
|---|
| 83 |
|
|---|
| 84 | static struct wprintf_int_test
|
|---|
| 85 | {
|
|---|
| 86 | int n;
|
|---|
| 87 | const wchar_t *format;
|
|---|
| 88 | const wchar_t *expected;
|
|---|
| 89 | } wprintf_int_tests[] =
|
|---|
| 90 | {
|
|---|
| 91 | { 0, L"%I'10d", L" " WZERO },
|
|---|
| 92 | { 1, L"%I'10d", L" " WONE },
|
|---|
| 93 | { 2, L"%I'10d", L" " WTWO },
|
|---|
| 94 | { 3, L"%I'10d", L" " WTHREE },
|
|---|
| 95 | { 4, L"%I'10d", L" " WFOUR },
|
|---|
| 96 | { 5, L"%I'10d", L" " WFIVE },
|
|---|
| 97 | { 6, L"%I'10d", L" " WSIX },
|
|---|
| 98 | { 7, L"%I'10d", L" " WSEVEN },
|
|---|
| 99 | { 8, L"%I'10d", L" " WEIGHT },
|
|---|
| 100 | { 9, L"%I'10d", L" " WNINE },
|
|---|
| 101 | { 11, L"%I'10d", L" " WONE WONE },
|
|---|
| 102 | { 12, L"%I'10d", L" " WONE WTWO },
|
|---|
| 103 | { 123, L"%I10d", L" " WONE WTWO WTHREE },
|
|---|
| 104 | { 123, L"%I'10d", L" " WONE WTWO WTHREE },
|
|---|
| 105 | { 1234, L"%I10d", L" " WONE WTWO WTHREE WFOUR },
|
|---|
| 106 | { 1234, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR },
|
|---|
| 107 | { 12345, L"%I'10d", L" " WONE WTWO L"," WTHREE WFOUR WFIVE },
|
|---|
| 108 | { 123456, L"%I'10d", L" " WONE WTWO WTHREE L"," WFOUR WFIVE WSIX },
|
|---|
| 109 | { 1234567, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR L"," WFIVE WSIX WSEVEN }
|
|---|
| 110 | };
|
|---|
| 111 | #define nwprintf_int_tests \
|
|---|
| 112 | (sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]))
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | int
|
|---|
| 116 | main (void)
|
|---|
| 117 | {
|
|---|
| 118 | int cnt;
|
|---|
| 119 | int failures;
|
|---|
| 120 | int status;
|
|---|
| 121 |
|
|---|
| 122 | if (setlocale (LC_ALL, "test7") == NULL)
|
|---|
| 123 | {
|
|---|
| 124 | puts ("cannot set locale `test7'");
|
|---|
| 125 | exit (1);
|
|---|
| 126 | }
|
|---|
| 127 | printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET));
|
|---|
| 128 |
|
|---|
| 129 | /* First: printf tests. */
|
|---|
| 130 | failures = 0;
|
|---|
| 131 | for (cnt = 0; cnt < (int) nprintf_int_tests; ++cnt)
|
|---|
| 132 | {
|
|---|
| 133 | char buf[100];
|
|---|
| 134 | ssize_t n;
|
|---|
| 135 |
|
|---|
| 136 | n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
|
|---|
| 137 | printf_int_tests[cnt].n);
|
|---|
| 138 |
|
|---|
| 139 | printf ("%3d: got \"%s\", expected \"%s\"",
|
|---|
| 140 | cnt, buf, printf_int_tests[cnt].expected);
|
|---|
| 141 |
|
|---|
| 142 | if (n != (ssize_t) strlen (printf_int_tests[cnt].expected)
|
|---|
| 143 | || strcmp (buf, printf_int_tests[cnt].expected) != 0)
|
|---|
| 144 | {
|
|---|
| 145 | puts (" -> FAILED");
|
|---|
| 146 | ++failures;
|
|---|
| 147 | }
|
|---|
| 148 | else
|
|---|
| 149 | puts (" -> OK");
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | printf ("%d failures in printf tests\n", failures);
|
|---|
| 153 | status = failures != 0;
|
|---|
| 154 |
|
|---|
| 155 | /* wprintf tests. */
|
|---|
| 156 | failures = 0;
|
|---|
| 157 | for (cnt = 0; cnt < (int) nwprintf_int_tests; ++cnt)
|
|---|
| 158 | {
|
|---|
| 159 | wchar_t buf[100];
|
|---|
| 160 | ssize_t n;
|
|---|
| 161 |
|
|---|
| 162 | n = swprintf (buf, sizeof buf / sizeof (buf[0]),
|
|---|
| 163 | wprintf_int_tests[cnt].format,
|
|---|
| 164 | wprintf_int_tests[cnt].n);
|
|---|
| 165 |
|
|---|
| 166 | printf ("%3d: got \"%ls\", expected \"%ls\"",
|
|---|
| 167 | cnt, buf, wprintf_int_tests[cnt].expected);
|
|---|
| 168 |
|
|---|
| 169 | if (n != (ssize_t) wcslen (wprintf_int_tests[cnt].expected)
|
|---|
| 170 | || wcscmp (buf, wprintf_int_tests[cnt].expected) != 0)
|
|---|
| 171 | {
|
|---|
| 172 | puts (" -> FAILED");
|
|---|
| 173 | ++failures;
|
|---|
| 174 | }
|
|---|
| 175 | else
|
|---|
| 176 | puts (" -> OK");
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | printf ("%d failures in wprintf tests\n", failures);
|
|---|
| 180 | status = failures != 0;
|
|---|
| 181 |
|
|---|
| 182 | /* ctype tests. This makes sure that the multibyte chracter digit
|
|---|
| 183 | representations are not handle in this table. */
|
|---|
| 184 | failures = 0;
|
|---|
| 185 | for (cnt = 0; cnt < 256; ++cnt)
|
|---|
| 186 | if (cnt >= '0' && cnt <= '9')
|
|---|
| 187 | {
|
|---|
| 188 | if (! isdigit (cnt))
|
|---|
| 189 | {
|
|---|
| 190 | printf ("isdigit ('%c') == 0\n", cnt);
|
|---|
| 191 | ++failures;
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 | else
|
|---|
| 195 | {
|
|---|
| 196 | if (isdigit (cnt))
|
|---|
| 197 | {
|
|---|
| 198 | printf ("isdigit (%d) != 0\n", cnt);
|
|---|
| 199 | ++failures;
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | printf ("%d failures in ctype tests\n", failures);
|
|---|
| 204 | status = failures != 0;
|
|---|
| 205 |
|
|---|
| 206 | /* wctype tests. This makes sure the second set of digits is also
|
|---|
| 207 | recorded. */
|
|---|
| 208 | failures = 0;
|
|---|
| 209 | for (cnt = 0; cnt < 256; ++cnt)
|
|---|
| 210 | if (cnt >= '0' && cnt <= '9')
|
|---|
| 211 | {
|
|---|
| 212 | if (! iswdigit (cnt))
|
|---|
| 213 | {
|
|---|
| 214 | printf ("iswdigit (L'%c') == 0\n", cnt);
|
|---|
| 215 | ++failures;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | else
|
|---|
| 219 | {
|
|---|
| 220 | if (iswdigit (cnt))
|
|---|
| 221 | {
|
|---|
| 222 | printf ("iswdigit (%d) != 0\n", cnt);
|
|---|
| 223 | ++failures;
|
|---|
| 224 | }
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | for (cnt = 0x2070; cnt < 0x2090; ++cnt)
|
|---|
| 228 | if (cnt >= 0x2080 && cnt <= 0x2089)
|
|---|
| 229 | {
|
|---|
| 230 | if (! iswdigit (cnt))
|
|---|
| 231 | {
|
|---|
| 232 | printf ("iswdigit (U%04X) == 0\n", cnt);
|
|---|
| 233 | ++failures;
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | else
|
|---|
| 237 | {
|
|---|
| 238 | if (iswdigit (cnt))
|
|---|
| 239 | {
|
|---|
| 240 | printf ("iswdigit (U%04X) != 0\n", cnt);
|
|---|
| 241 | ++failures;
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | printf ("%d failures in wctype tests\n", failures);
|
|---|
| 246 | status = failures != 0;
|
|---|
| 247 |
|
|---|
| 248 | return status;
|
|---|
| 249 | }
|
|---|