about summary refs log tree commit diff
path: root/posix/tst-regex.c
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@redhat.com>2021-09-01 15:19:19 -0400
committerCarlos O'Donell <carlos@redhat.com>2021-09-06 11:30:28 -0400
commit466f2be6c08070e9113ae2fdc7acd5d8828cba50 (patch)
treec4fb7c10d98994298dcd451df71f1be790b575e9 /posix/tst-regex.c
parentf5117c6504888fab5423282a4607c552b90fd3f9 (diff)
downloadglibc-466f2be6c08070e9113ae2fdc7acd5d8828cba50.tar.gz
glibc-466f2be6c08070e9113ae2fdc7acd5d8828cba50.tar.xz
glibc-466f2be6c08070e9113ae2fdc7acd5d8828cba50.zip
Add generic C.UTF-8 locale (Bug 17318)
We add a new C.UTF-8 locale. This locale is not builtin to glibc, but
is provided as a distinct locale. The locale provides full support for
UTF-8 and this includes full code point sorting via STRCMP-based
collation (strcmp or wcscmp).

The collation uses a new keyword 'codepoint_collation' which drops all
collation rules and generates an empty zero rules collation to enable
STRCMP usage in collation. This ensures that we get full code point
sorting for C.UTF-8 with a minimal 1406 bytes of overhead (LC_COLLATE
structure information and ASCII collating tables).

The new locale is added to SUPPORTED. Minimal test data for specific
code points (minus those not supported by collate-test) is provided in
C.UTF-8.in, and this verifies code point sorting is working reasonably
across the range. The locale was tested manually with the full set of
code points without failure.

The locale is harmonized with locales already shipping in various
downstream distributions. A new tst-iconv9 test is added which verifies
the C.UTF-8 locale is generally usable.

Testing for fnmatch, regexec, and recomp is provided by extending
bug-regex1, bugregex19, bug-regex4, bug-regex6, transbug, tst-fnmatch,
tst-regcomp-truncated, and tst-regex to use C.UTF-8.

Tested on x86_64 or i686 without regression.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'posix/tst-regex.c')
-rw-r--r--posix/tst-regex.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/posix/tst-regex.c b/posix/tst-regex.c
index e7c2b05e86..531128de2a 100644
--- a/posix/tst-regex.c
+++ b/posix/tst-regex.c
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <regex.h>
+#include <support/support.h>
 
 
 #if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
@@ -58,7 +59,7 @@ do_test (void)
   const char *file;
   int fd;
   struct stat st;
-  int result;
+  int result = 0;
   char *inmem;
   char *outmem;
   size_t inlen;
@@ -123,7 +124,7 @@ do_test (void)
 
   /* Run the actual tests.  All tests are run in a single-byte and a
      multi-byte locale.  */
-  result = test_expr ("[äáàâéèêíìîñöóòôüúùû]", 4, 4);
+  result |= test_expr ("[äáàâéèêíìîñöóòôüúùû]", 4, 4);
   result |= test_expr ("G.ran", 2, 3);
   result |= test_expr ("G.\\{1\\}ran", 2, 3);
   result |= test_expr ("G.*ran", 3, 44);
@@ -143,19 +144,33 @@ do_test (void)
 static int
 test_expr (const char *expr, int expected, int expectedicase)
 {
-  int result;
+  int result = 0;
   char *inmem;
   char *outmem;
   size_t inlen;
   size_t outlen;
   char *uexpr;
 
-  /* First test: search with an UTF-8 locale.  */
-  if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
-    error (EXIT_FAILURE, 0, "cannot set locale de_DE.UTF-8");
+  /* First test: search with basic C.UTF-8 locale.  */
+  printf ("INFO: Testing C.UTF-8.\n");
+  xsetlocale (LC_ALL, "C.UTF-8");
 
   printf ("\nTest \"%s\" with multi-byte locale\n", expr);
-  result = run_test (expr, mem, memlen, 0, expected);
+  result |= run_test (expr, mem, memlen, 0, expected);
+  printf ("\nTest \"%s\" with multi-byte locale, case insensitive\n", expr);
+  result |= run_test (expr, mem, memlen, 1, expectedicase);
+  printf ("\nTest \"%s\" backwards with multi-byte locale\n", expr);
+  result |= run_test_backwards (expr, mem, memlen, 0, expected);
+  printf ("\nTest \"%s\" backwards with multi-byte locale, case insensitive\n",
+	  expr);
+  result |= run_test_backwards (expr, mem, memlen, 1, expectedicase);
+
+  /* Second test: search with an UTF-8 locale.  */
+  printf ("INFO: Testing de_DE.UTF-8.\n");
+  xsetlocale (LC_ALL, "de_DE.UTF-8");
+
+  printf ("\nTest \"%s\" with multi-byte locale\n", expr);
+  result |= run_test (expr, mem, memlen, 0, expected);
   printf ("\nTest \"%s\" with multi-byte locale, case insensitive\n", expr);
   result |= run_test (expr, mem, memlen, 1, expectedicase);
   printf ("\nTest \"%s\" backwards with multi-byte locale\n", expr);
@@ -165,8 +180,8 @@ test_expr (const char *expr, int expected, int expectedicase)
   result |= run_test_backwards (expr, mem, memlen, 1, expectedicase);
 
   /* Second test: search with an ISO-8859-1 locale.  */
-  if (setlocale (LC_ALL, "de_DE.ISO-8859-1") == NULL)
-    error (EXIT_FAILURE, 0, "cannot set locale de_DE.ISO-8859-1");
+  printf ("INFO: Testing de_DE.ISO-8859-1.\n");
+  xsetlocale (LC_ALL, "de_DE.ISO-8859-1");
 
   inmem = (char *) expr;
   inlen = strlen (expr);