2001-03-19 22:40:15 +01:00
|
|
|
/* Based on a test case by Paul Eggert. */
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
char const string[] = "";
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
test (const char *locale)
|
|
|
|
{
|
|
|
|
size_t bufsize;
|
|
|
|
size_t r;
|
|
|
|
size_t l;
|
|
|
|
char *buf;
|
2002-08-29 11:26:30 +02:00
|
|
|
locale_t loc;
|
2001-03-19 22:40:15 +01:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (setlocale (LC_COLLATE, locale) == NULL)
|
|
|
|
{
|
|
|
|
printf ("cannot set locale \"%s\"\n", locale);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bufsize = strxfrm (NULL, string, 0) + 1;
|
|
|
|
buf = malloc (bufsize);
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
printf ("cannot allocate %zd bytes\n", bufsize);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
r = strxfrm (buf, string, bufsize);
|
|
|
|
l = strlen (buf);
|
|
|
|
if (r != l)
|
|
|
|
{
|
|
|
|
printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
|
|
|
|
locale, r, l);
|
|
|
|
result = 1;
|
|
|
|
}
|
2001-10-27 05:00:50 +02:00
|
|
|
|
2002-08-29 11:26:30 +02:00
|
|
|
loc = newlocale (1 << LC_ALL, locale, NULL);
|
2001-10-27 05:00:50 +02:00
|
|
|
|
2002-08-29 11:26:30 +02:00
|
|
|
r = strxfrm_l (buf, string, bufsize, loc);
|
2001-10-27 05:00:50 +02:00
|
|
|
l = strlen (buf);
|
|
|
|
if (r != l)
|
|
|
|
{
|
|
|
|
printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
|
|
|
|
locale, r, l);
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
2002-08-29 11:26:30 +02:00
|
|
|
freelocale (loc);
|
2001-10-27 05:00:50 +02:00
|
|
|
|
2001-03-19 22:40:15 +01:00
|
|
|
free (buf);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-05 10:54:08 +01:00
|
|
|
static int
|
|
|
|
do_test (void)
|
2001-03-19 22:40:15 +01:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
result |= test ("C");
|
|
|
|
result |= test ("en_US.ISO-8859-1");
|
|
|
|
result |= test ("de_DE.UTF-8");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2014-11-05 10:54:08 +01:00
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|