Define CMPLX macros for more _FloatN, _FloatNx types.
[glibc.git] / string / tst-strxfrm.c
blobffe191c60d9a290f19deab6b001d8f789fdaa0c4
1 /* Based on a test case by Paul Eggert. */
2 #include <locale.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
8 char const string[] = "";
11 static int
12 test (const char *locale)
14 size_t bufsize;
15 size_t r;
16 size_t l;
17 char *buf;
18 locale_t loc;
19 int result = 0;
21 if (setlocale (LC_COLLATE, locale) == NULL)
23 printf ("cannot set locale \"%s\"\n", locale);
24 return 1;
26 bufsize = strxfrm (NULL, string, 0) + 1;
27 buf = malloc (bufsize);
28 if (buf == NULL)
30 printf ("cannot allocate %zd bytes\n", bufsize);
31 return 1;
33 r = strxfrm (buf, string, bufsize);
34 l = strlen (buf);
35 if (r != l)
37 printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
38 locale, r, l);
39 result = 1;
42 loc = newlocale (1 << LC_ALL, locale, NULL);
44 r = strxfrm_l (buf, string, bufsize, loc);
45 l = strlen (buf);
46 if (r != l)
48 printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
49 locale, r, l);
50 result = 1;
53 freelocale (loc);
55 free (buf);
57 return result;
61 int
62 do_test (void)
64 int result = 0;
66 result |= test ("C");
67 result |= test ("en_US.ISO-8859-1");
68 result |= test ("de_DE.UTF-8");
70 return result;
73 #include <support/test-driver.c>