|
Packit |
6c4009 |
/* Test restarting behaviour of mbsnrtowcs.
|
|
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 Bruno Haible <haible@ilog.fr>.
|
|
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 <stdio.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <wchar.h>
|
|
Packit |
6c4009 |
#include <locale.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define show(expr, nexp, wcexp, end) \
|
|
Packit |
6c4009 |
n = expr; \
|
|
Packit |
6c4009 |
printf (#expr " -> %zu", n); \
|
|
Packit |
6c4009 |
printf (", wc = %lu, src = buf+%td", (unsigned long int) wc, \
|
|
Packit |
6c4009 |
src - (const char *) buf); \
|
|
Packit |
6c4009 |
if (n != (size_t) nexp || wc != wcexp || src != (const char *) (end)) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
printf (", expected %zu and %lu and buf+%td", (size_t) nexp, \
|
|
Packit |
6c4009 |
(unsigned long int) wcexp, (end) - buf); \
|
|
Packit |
6c4009 |
result = 1; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
putc ('\n', stdout)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
unsigned char buf[6] = { 0x25, 0xe2, 0x82, 0xac, 0xce, 0xbb };
|
|
Packit |
6c4009 |
mbstate_t state;
|
|
Packit |
6c4009 |
const char *src;
|
|
Packit |
6c4009 |
wchar_t wc = 42;
|
|
Packit |
6c4009 |
size_t n;
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
const char *used_locale;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
setlocale (LC_CTYPE,"de_DE.UTF-8");
|
|
Packit |
6c4009 |
/* Double check. */
|
|
Packit |
6c4009 |
used_locale = setlocale (LC_CTYPE, NULL);
|
|
Packit |
6c4009 |
printf ("used locale: \"%s\"\n", used_locale);
|
|
Packit |
6c4009 |
result = strcmp (used_locale, "de_DE.UTF-8");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
memset (&state, '\0', sizeof (state));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
src = (const char *) buf;
|
|
Packit |
6c4009 |
show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 37, buf + 1);
|
|
Packit |
6c4009 |
show (mbsnrtowcs (&wc, &src, 3, 1, &state), 1, 8364, buf + 4);
|
|
Packit |
6c4009 |
show (mbsnrtowcs (&wc, &src, 1, 1, &state), 0, 8364, buf + 5);
|
|
Packit |
6c4009 |
show (mbsnrtowcs (&wc, &src, 1, 1, &state), 1, 955, buf + 6);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|