source: branches/libc-0.6/src/libctests/glibc/string/tst-strxfrm.c

Last change on this file was 2076, checked in by bird, 20 years ago

libc adjustments. extending some testcases.

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
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>
6
7
8static int
9test (const char *locale, const char *string)
10{
11 size_t bufsize;
12 size_t r;
13 size_t l;
14 char *buf;
15#ifdef HAVE_NEWLOCALE
16 locale_t loc;
17#endif
18 int result = 0;
19
20 if (setlocale (LC_COLLATE, locale) == NULL)
21 {
22 printf ("cannot set locale \"%s\"\n", locale);
23 return 1;
24 }
25 bufsize = strxfrm (NULL, string, 0) + 1;
26 buf = malloc (bufsize);
27 if (buf == NULL)
28 {
29 printf ("cannot allocate %zd bytes\n", bufsize);
30 return 1;
31 }
32 r = strxfrm (buf, string, bufsize);
33 l = strlen (buf);
34 if (r != l)
35 {
36 printf ("locale \"%s\": strxfrm returned %zu, strlen returned %zu\n",
37 locale, r, l);
38 result = 1;
39 }
40
41#ifdef HAVE_NEWLOCALE
42 loc = newlocale (1 << LC_ALL, locale, NULL);
43
44 r = strxfrm_l (buf, string, bufsize, loc);
45 l = strlen (buf);
46 if (r != l)
47 {
48 printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n",
49 locale, r, l);
50 result = 1;
51 }
52
53 freelocale (loc);
54#endif
55
56 free (buf);
57
58 return result;
59}
60
61
62int
63main (void)
64{
65 int result = 0;
66
67 result |= test ("C", "");
68 result |= test ("C", "abcABCxyzXYZ|+-/*(%$");
69#ifdef __BSD__ /* BSD is missing the aliases. loosers. */
70 result |= test ("en_US.ISO8859-1", "");
71 result |= test ("en_US.ISO8859-1", "abcABCxyzXYZ|+-/*(%$");
72#else
73 result |= test ("en_US.ISO-8859-1", "");
74 result |= test ("en_US.ISO-8859-1", "abcABCxyzXYZ|+-/*(%$");
75#endif
76 result |= test ("de_DE.UTF-8", "");
77 result |= test ("de_DE.UTF-8", "abcABCxyzXYZ|+-/*(%$");
78
79 return result;
80}
Note: See TracBrowser for help on using the repository browser.