Blame string/tst-strxfrm.c
|
Packit |
6c4009 |
/* Based on a test case by Paul Eggert. */
|
|
Packit |
6c4009 |
#include <locale.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char const string[] = "";
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
test (const char *locale)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
size_t bufsize;
|
|
Packit |
6c4009 |
size_t r;
|
|
Packit |
6c4009 |
size_t l;
|
|
Packit |
6c4009 |
char *buf;
|
|
Packit |
6c4009 |
locale_t loc;
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (setlocale (LC_COLLATE, locale) == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("cannot set locale \"%s\"\n", locale);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
bufsize = strxfrm (NULL, string, 0) + 1;
|
|
Packit |
6c4009 |
buf = malloc (bufsize);
|
|
Packit |
6c4009 |
if (buf == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("cannot allocate %zd bytes\n", bufsize);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
r = strxfrm (buf, string, bufsize);
|
|
Packit |
6c4009 |
l = strlen (buf);
|
|
Packit |
6c4009 |
if (r != l)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
|
|
Packit |
6c4009 |
locale, r, l);
|
|
Packit |
6c4009 |
result = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
loc = newlocale (1 << LC_ALL, locale, NULL);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
r = strxfrm_l (buf, string, bufsize, loc);
|
|
Packit |
6c4009 |
l = strlen (buf);
|
|
Packit |
6c4009 |
if (r != l)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
|
|
Packit |
6c4009 |
locale, r, l);
|
|
Packit |
6c4009 |
result = 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
freelocale (loc);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
free (buf);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
result |= test ("C");
|
|
Packit |
6c4009 |
result |= test ("en_US.ISO-8859-1");
|
|
Packit |
6c4009 |
result |= test ("de_DE.UTF-8");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|