diff options
author | Mike Frysinger <vapier@gentoo.org> | 2006-02-14 02:48:22 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2006-02-14 02:48:22 +0000 |
commit | 400925d81cc92de52efe6cad6dcc33794262119c (patch) | |
tree | 06b7e50e991a816df1dab204cada9254d751bb96 | |
parent | 54d2ed80d418a3afd2b80fcba7646bd806627ecc (diff) |
grab a bunch of tests from glibc
-rw-r--r-- | test/string/Makefile | 4 | ||||
-rw-r--r-- | test/string/bug-strcoll1.c | 24 | ||||
-rw-r--r-- | test/string/bug-strncat1.c | 31 | ||||
-rw-r--r-- | test/string/bug-strpbrk1.c | 19 | ||||
-rw-r--r-- | test/string/bug-strspn1.c | 19 | ||||
-rw-r--r-- | test/string/stratcliff.c | 349 | ||||
-rw-r--r-- | test/string/test-ffs.c | 66 | ||||
-rw-r--r-- | test/string/tst-bswap.c | 74 | ||||
-rw-r--r-- | test/string/tst-inlcall.c | 83 | ||||
-rw-r--r-- | test/string/tst-strlen.c | 45 | ||||
-rw-r--r-- | test/string/tst-strtok.c | 23 | ||||
-rw-r--r-- | test/string/tst-strxfrm.c | 80 |
12 files changed, 816 insertions, 1 deletions
diff --git a/test/string/Makefile b/test/string/Makefile index 67fd415c8..4a3cecfd3 100644 --- a/test/string/Makefile +++ b/test/string/Makefile @@ -1,6 +1,8 @@ # uClibc string tests # Licensed under the GNU Library General Public License, see COPYING.LIB -TESTS := testcopy tester +TESTS := $(patsubst %.c,%,$(wildcard *.c)) include ../Test.mak + +EXTRA_CFLAGS := -fno-builtin diff --git a/test/string/bug-strcoll1.c b/test/string/bug-strcoll1.c new file mode 100644 index 000000000..b6510d926 --- /dev/null +++ b/test/string/bug-strcoll1.c @@ -0,0 +1,24 @@ +#include <stdio.h> +#include <string.h> +#include <locale.h> + +int +main (void) +{ + const char t1[] = "0-0-0-0-0-0-0-0-0-0.COM"; + const char t2[] = "00000-00000.COM"; + int res1; + int res2; + + setlocale (LC_ALL, "en_US.ISO-8859-1"); + + res1 = strcoll (t1, t2); + printf ("strcoll (\"%s\", \"%s\") = %d\n", t1, t2, res1); + res2 = strcoll (t2, t1); + printf ("strcoll (\"%s\", \"%s\") = %d\n", t2, t1, res2); + + return ((res1 == 0 && res2 != 0) + || (res1 != 0 && res2 == 0) + || (res1 < 0 && res2 < 0) + || (res1 > 0 && res2 > 0)); +} diff --git a/test/string/bug-strncat1.c b/test/string/bug-strncat1.c new file mode 100644 index 000000000..f1b5c37c5 --- /dev/null +++ b/test/string/bug-strncat1.c @@ -0,0 +1,31 @@ +/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */ +#undef __USE_STRING_INLINES +#define __USE_STRING_INLINES +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char d[3] = "\0\1\2"; + +int +main (void) +{ + strncat (d, "\5\6", 1); + if (d[0] != '\5') + { + puts ("d[0] != '\\5'"); + exit (1); + } + if (d[1] != '\0') + { + puts ("d[1] != '\\0'"); + exit (1); + } + if (d[2] != '\2') + { + puts ("d[2] != '\\2'"); + exit (1); + } + + return 0; +} diff --git a/test/string/bug-strpbrk1.c b/test/string/bug-strpbrk1.c new file mode 100644 index 000000000..28238b0f5 --- /dev/null +++ b/test/string/bug-strpbrk1.c @@ -0,0 +1,19 @@ +/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */ +#undef __USE_STRING_INLINES +#define __USE_STRING_INLINES +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +int +main (void) +{ + const char *a = "abc"; + const char *b = a; + + strpbrk (b++, ""); + if (b != a + 1) + return 1; + + return 0; +} diff --git a/test/string/bug-strspn1.c b/test/string/bug-strspn1.c new file mode 100644 index 000000000..a657bafc4 --- /dev/null +++ b/test/string/bug-strspn1.c @@ -0,0 +1,19 @@ +/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */ +#undef __USE_STRING_INLINES +#define __USE_STRING_INLINES +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +int +main (void) +{ + const char *a = "abc"; + const char *b = a; + + strspn (b++, ""); + if (b != a + 1) + return 1; + + return 0; +} diff --git a/test/string/stratcliff.c b/test/string/stratcliff.c new file mode 100644 index 000000000..6377c6ed7 --- /dev/null +++ b/test/string/stratcliff.c @@ -0,0 +1,349 @@ +/* Test for string function add boundaries of usable memory. + Copyright (C) 1996,1997,1999-2002,2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define _GNU_SOURCE 1 + +/* Make sure we don't test the optimized inline functions if we want to + test the real implementation. */ +#undef __USE_STRING_INLINES + +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/param.h> + +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + +int +main (int argc, char *argv[]) +{ + int size = sysconf (_SC_PAGESIZE); + char *adr, *dest; + int result = 0; + + adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (adr == MAP_FAILED || dest == MAP_FAILED) + { + if (errno == ENOSYS) + puts ("No test, mmap not available."); + else + { + printf ("mmap failed: %m"); + result = 1; + } + } + else + { + int inner, middle, outer; + + mprotect(adr, size, PROT_NONE); + mprotect(adr + 2 * size, size, PROT_NONE); + adr += size; + + mprotect(dest, size, PROT_NONE); + mprotect(dest + 2 * size, size, PROT_NONE); + dest += size; + + memset (adr, 'T', size); + + /* strlen test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (inner = MAX (outer, size - 64); inner < size; ++inner) + { + adr[inner] = '\0'; + + if (strlen (&adr[outer]) != (size_t) (inner - outer)) + { + printf ("strlen flunked for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + + adr[inner] = 'T'; + } + } + + /* strchr test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (middle = MAX (outer, size - 64); middle < size; ++middle) + { + for (inner = middle; inner < size; ++inner) + { + char *cp; + adr[middle] = 'V'; + adr[inner] = '\0'; + + cp = strchr (&adr[outer], 'V'); + + if ((inner == middle && cp != NULL) + || (inner != middle + && (cp - &adr[outer]) != middle - outer)) + { + printf ("strchr flunked for outer = %d, middle = %d, " + "inner = %d\n", outer, middle, inner); + result = 1; + } + + adr[inner] = 'T'; + adr[middle] = 'T'; + } + } + } + + /* Special test. */ + adr[size - 1] = '\0'; + if (strchr (&adr[size - 1], '\n') != NULL) + { + puts ("strchr flunked for test of empty string at end of page"); + result = 1; + } + + /* strrchr test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (middle = MAX (outer, size - 64); middle < size; ++middle) + { + for (inner = middle; inner < size; ++inner) + { + char *cp; + adr[middle] = 'V'; + adr[inner] = '\0'; + + cp = strrchr (&adr[outer], 'V'); + + if ((inner == middle && cp != NULL) + || (inner != middle + && (cp - &adr[outer]) != middle - outer)) + { + printf ("strrchr flunked for outer = %d, middle = %d, " + "inner = %d\n", outer, middle, inner); + result = 1; + } + + adr[inner] = 'T'; + adr[middle] = 'T'; + } + } + } + + /* rawmemchr test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (middle = MAX (outer, size - 64); middle < size; ++middle) + { + char *cp; + adr[middle] = 'V'; + + cp = rawmemchr (&adr[outer], 'V'); + + if (cp - &adr[outer] != middle - outer) + { + printf ("rawmemchr flunked for outer = %d, middle = %d\n", + outer, middle); + result = 1; + } + + adr[middle] = 'T'; + } + } + + /* strcpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (inner = MAX (outer, size - 64); inner < size; ++inner) + { + adr[inner] = '\0'; + + if (strcpy (dest, &adr[outer]) != dest + || strlen (dest) != (size_t) (inner - outer)) + { + printf ("strcpy flunked for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + + adr[inner] = 'T'; + } + } + + /* strncpy tests */ + adr[size-1] = 'T'; + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + size_t len; + + for (len = 0; len < size - outer; ++len) + { + if (strncpy (dest, &adr[outer], len) != dest + || memcmp (dest, &adr[outer], len) != 0) + { + printf ("outer strncpy flunked for outer = %d, len = %Zd\n", + outer, len); + result = 1; + } + } + } + adr[size-1] = '\0'; + + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (inner = MAX (outer, size - 64); inner < size; ++inner) + { + size_t len; + + adr[inner] = '\0'; + + for (len = 0; len < size - outer + 64; ++len) + { + if (strncpy (dest, &adr[outer], len) != dest + || memcmp (dest, &adr[outer], + MIN (inner - outer, len)) != 0 + || (inner - outer < len + && strlen (dest) != (inner - outer))) + { + printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n", + outer, inner, len); + result = 1; + } + if (strncpy (dest + 1, &adr[outer], len) != dest + 1 + || memcmp (dest + 1, &adr[outer], + MIN (inner - outer, len)) != 0 + || (inner - outer < len + && strlen (dest + 1) != (inner - outer))) + { + printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n", + outer, inner, len); + result = 1; + } + } + + adr[inner] = 'T'; + } + } + + /* stpcpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (inner = MAX (outer, size - 64); inner < size; ++inner) + { + adr[inner] = '\0'; + + if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer) + { + printf ("stpcpy flunked for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + + adr[inner] = 'T'; + } + } + + /* stpncpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + { + for (middle = MAX (outer, size - 64); middle < size; ++middle) + { + adr[middle] = '\0'; + + for (inner = 0; inner < size - outer; ++ inner) + { + if ((stpncpy (dest, &adr[outer], inner) - dest) + != MIN (inner, middle - outer)) + { + printf ("stpncpy flunked for outer = %d, middle = %d, " + "inner = %d\n", outer, middle, inner); + result = 1; + } + } + + adr[middle] = 'T'; + } + } + + /* memcpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + for (inner = 0; inner < size - outer; ++inner) + if (memcpy (dest, &adr[outer], inner) != dest) + { + printf ("memcpy flunked for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + + /* mempcpy test */ + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + for (inner = 0; inner < size - outer; ++inner) + if (mempcpy (dest, &adr[outer], inner) != dest + inner) + { + printf ("mempcpy flunked for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + + /* memccpy test */ + memset (adr, '\0', size); + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + for (inner = 0; inner < size - outer; ++inner) + if (memccpy (dest, &adr[outer], '\1', inner) != NULL) + { + printf ("memccpy flunked full copy for outer = %d, inner = %d\n", + outer, inner); + result = 1; + } + for (outer = size - 1; outer >= MAX (0, size - 128); --outer) + for (middle = 0; middle < size - outer; ++middle) + { + memset (dest, '\2', middle + 1); + for (inner = 0; inner < middle; ++inner) + { + adr[outer + inner] = '\1'; + + if (memccpy (dest, &adr[outer], '\1', middle + 128) + != dest + inner + 1) + { + printf ("\ +memccpy flunked partial copy for outer = %d, middle = %d, inner = %d\n", + outer, middle, inner); + result = 1; + } + else if (dest[inner + 1] != '\2') + { + printf ("\ +memccpy copied too much for outer = %d, middle = %d, inner = %d\n", + outer, middle, inner); + result = 1; + } + adr[outer + inner] = '\0'; + } + } + } + + return result; +} diff --git a/test/string/test-ffs.c b/test/string/test-ffs.c new file mode 100644 index 000000000..86e11758d --- /dev/null +++ b/test/string/test-ffs.c @@ -0,0 +1,66 @@ +/* Copyright (C) 1994, 1997, 2000, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil), + On-Line Applications Research Corporation. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + int failures = 0; + int i; + + auto void try (const char *name, long long int param, int value, + int expected); + + void try (const char *name, long long int param, int value, int expected) + { + if (value != expected) + { + printf ("%s(%#llx) expected %d got %d\n", + name, param, expected, value); + ++failures; + } + else + printf ("%s(%#llx) as expected %d\n", name, param, value); + } + +#define TEST(fct, type) \ + try (#fct, 0, fct ((type) 0), 0); \ + for (i=0 ; i < 8 * sizeof (type); i++) \ + try (#fct, 1ll << i, fct (((type) 1) << i), i + 1); \ + for (i=0 ; i < 8 * sizeof (type) ; i++) \ + try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\ + try (#fct, 0x80008000, fct ((type) 0x80008000), 16) + + TEST (ffs, int); +/* Not implemented in uClibc (yet?) + TEST (ffsl, long int); + TEST (ffsll, long long int); +*/ + + if (failures) + printf ("Test FAILED! %d failure%s.\n", failures, &"s"[failures == 1]); + else + puts ("Test succeeded."); + + return failures; +} diff --git a/test/string/tst-bswap.c b/test/string/tst-bswap.c new file mode 100644 index 000000000..b2b4ef08d --- /dev/null +++ b/test/string/tst-bswap.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <byteswap.h> +#include <stdio.h> + +extern unsigned long long int wash (unsigned long long int a); + +int +main (void) +{ + int result = 0; + + /* Test the functions with constant arguments. */ + if (bswap_16 (0x1234) != 0x3412) + { + puts ("bswap_16 (constant) flunked"); + result = 1; + } + if (bswap_32 (0x12345678) != 0x78563412) + { + puts ("bswap_32 (constant) flunked"); + result = 1; + } + if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL) + { + puts ("bswap_64 (constant) flunked"); + result = 1; + } + + /* Test the functions with non-constant arguments. */ + if (bswap_16 (wash (0x1234)) != 0x3412) + { + puts ("bswap_16 (non-constant) flunked"); + result = 1; + } + if (bswap_32 (wash (0x12345678)) != 0x78563412) + { + puts ("bswap_32 (non-constant) flunked"); + result = 1; + } + if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL) + { + puts ("bswap_64 (non-constant) flunked"); + result = 1; + } + + return result; +} + + +unsigned long long int +wash (unsigned long long int a) +{ + /* Do nothing. This function simply exists to avoid that the compiler + regards the argument to the bswap_*() functions as constant. */ + return a + 0; +} diff --git a/test/string/tst-inlcall.c b/test/string/tst-inlcall.c new file mode 100644 index 000000000..2a4124ea5 --- /dev/null +++ b/test/string/tst-inlcall.c @@ -0,0 +1,83 @@ +/* Tester for calling inline string functions. + Copyright (C) 1998, 2000, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +/* Make sure we test the optimized inline functions. */ +#define __USE_STRING_INLINES 1 + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <fcntl.h> + + +int +main (void) +{ + int status; + int errors = 0; + char buf1[1000]; + char *cp; + char ch; + + cp = strcpy (buf1, "hello world"); + if (strcmp ("hello world", cp++) != 0) + { + puts ("strcmp test 1 failed"); + ++errors; + } + + cp = buf1; + if (strcmp (cp++, "hello world") != 0) + { + puts ("strcmp test 2 failed"); + ++errors; + } + + ch = 'h'; + if (strchr ("hello world", ch++) == NULL) + { + puts ("strchr test 1 failed"); + ++errors; + } + + const char * const hw = "hello world"; + if (strpbrk (hw, "o") - hw != 4) + { + puts ("strpbrk test 1 failed"); + ++errors; + } + + if (errors == 0) + { + status = EXIT_SUCCESS; + puts ("No errors."); + } + else + { + status = EXIT_FAILURE; + printf ("%d errors.\n", errors); + } + return status; +} diff --git a/test/string/tst-strlen.c b/test/string/tst-strlen.c new file mode 100644 index 000000000..a1e115927 --- /dev/null +++ b/test/string/tst-strlen.c @@ -0,0 +1,45 @@ +/* Make sure we don't test the optimized inline functions if we want to + test the real implementation. */ +#undef __USE_STRING_INLINES + +#include <stdio.h> +#include <string.h> + +int +main(int argc, char *argv[]) +{ + static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3, + 0, 1, 0, 2, 0, 1, 0, 4 }; + char basebuf[24 + 32]; + size_t base; + + for (base = 0; base < 32; ++base) + { + char *buf = basebuf + base; + size_t words; + + for (words = 0; words < 4; ++words) + { + size_t last; + memset (buf, 'a', words * 4); + + for (last = 0; last < 16; ++last) + { + buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0'; + buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0'; + buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0'; + buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0'; + buf[words * 4 + 4] = '\0'; + + if (strlen (buf) != words * 4 + lens[last] + || strnlen (buf, -1) != words * 4 + lens[last]) + { + printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n", + base, words, last); + return 1; + } + } + } + } + return 0; +} diff --git a/test/string/tst-strtok.c b/test/string/tst-strtok.c new file mode 100644 index 000000000..7e34aeefa --- /dev/null +++ b/test/string/tst-strtok.c @@ -0,0 +1,23 @@ +/* Testcase for strtok reported by Andrew Church <achurch@achurch.org>. */ +#include <stdio.h> +#include <string.h> + +int +main (void) +{ + char buf[1] = { 0 }; + int result = 0; + + if (strtok (buf, " ") != NULL) + { + puts ("first strtok call did not return NULL"); + result = 1; + } + else if (strtok (NULL, " ") != NULL) + { + puts ("second strtok call did not return NULL"); + result = 1; + } + + return result; +} diff --git a/test/string/tst-strxfrm.c b/test/string/tst-strxfrm.c new file mode 100644 index 000000000..f1c036bcb --- /dev/null +++ b/test/string/tst-strxfrm.c @@ -0,0 +1,80 @@ +/* Based on a test case by Paul Eggert. */ +#include <features.h> +#ifdef __UCLIBC_HAS_LOCALE__ +#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; + locale_t loc; + 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; + } + + loc = newlocale (1 << LC_ALL, locale, NULL); + + r = strxfrm_l (buf, string, bufsize, loc); + l = strlen (buf); + if (r != l) + { + printf ("locale \"%s\": strxfrm_l returned %zu, strlen returned %zu\n", + locale, r, l); + result = 1; + } + + freelocale (loc); + + free (buf); + + return result; +} + + +int +main (void) +{ + int result = 0; + + result |= test ("C"); + result |= test ("en_US.ISO-8859-1"); + result |= test ("de_DE.UTF-8"); + + return result; +} + +#else +int main(void) +{ + return 0; +} +#endif |