|
Packit |
6c4009 |
/* Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <locale.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <wchar.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int check_ascii (const char *locname);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check mapping of ASCII range for some character sets which have
|
|
Packit |
6c4009 |
ASCII as a subset. For those the wide char generated must have
|
|
Packit |
6c4009 |
the same value. */
|
|
Packit |
6c4009 |
setlocale (LC_ALL, "C");
|
|
Packit |
6c4009 |
result |= check_ascii (setlocale (LC_ALL, NULL));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
setlocale (LC_ALL, "de_DE.UTF-8");
|
|
Packit |
6c4009 |
result |= check_ascii (setlocale (LC_ALL, NULL));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
setlocale (LC_ALL, "ja_JP.EUC-JP");
|
|
Packit |
6c4009 |
result |= check_ascii (setlocale (LC_ALL, NULL));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
check_ascii (const char *locname)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
wchar_t wc;
|
|
Packit |
6c4009 |
int res = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
printf ("Testing locale \"%s\":\n", locname);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (wc = 0; wc <= 127; ++wc)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
char buf[2 * MB_CUR_MAX];
|
|
Packit |
6c4009 |
mbstate_t s;
|
|
Packit |
6c4009 |
size_t n;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
memset (buf, '\xff', sizeof (buf));
|
|
Packit |
6c4009 |
memset (&s, '\0', sizeof (s));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
n = wcrtomb (buf, wc, &s);
|
|
Packit |
6c4009 |
if (n == (size_t) -1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("%s: '\\x%x': encoding error\n", locname, (int) wc);
|
|
Packit |
6c4009 |
++res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (n == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("%s: '\\x%x': 0 returned\n", locname, (int) wc);
|
|
Packit |
6c4009 |
++res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (n != 1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("%s: '\\x%x': not 1 returned\n", locname, (int) wc);
|
|
Packit |
6c4009 |
++res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (wc != (wchar_t) buf[0])
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("%s: L'\\x%x': buf[0] != '\\x%x'\n", locname, (int) wc,
|
|
Packit |
6c4009 |
(int) wc);
|
|
Packit |
6c4009 |
++res;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
printf (res == 1 ? "%d error\n" : "%d errors\n", res);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return res != 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|