]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
mbspcasecmp tests: Enhance tests.
authorBruno Haible <bruno@clisp.org>
Mon, 25 May 2026 16:32:18 +0000 (18:32 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 25 May 2026 16:32:18 +0000 (18:32 +0200)
* tests/test-mbspcasecmp.c (test_ascii): New function, extracted from
main.
(test_utf_8): Likewise. Add test cases with incomplete characters.
(main): Invoke them. Accept a numeric argument.
* tests/test-mbspcasecmp-4.sh: Renamed from tests/test-mbspcasecmp.sh.
* tests/test-mbspcasecmp-3.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* modules/mbspcasecmp-tests (Files): Update after rename. Add
locale-en.m4, locale-fr.m4.
(configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
(Makefile.am): Arrange to run test-mbspcasecmp-3.sh,
test-mbspcasecmp-4.sh, instead of test-mbspcasecmp.sh.

ChangeLog
modules/mbspcasecmp-tests
tests/test-mbspcasecmp-3.sh [new file with mode: 0755]
tests/test-mbspcasecmp-4.sh [moved from tests/test-mbspcasecmp.sh with 89% similarity]
tests/test-mbspcasecmp.c

index 14ce0d68fde1510ea2d04bae2205b3549f5b61f3..c5b5e39291a4a69f9af91c188487dc62d75365b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2026-05-25  Bruno Haible  <bruno@clisp.org>
+
+       mbspcasecmp tests: Enhance tests.
+       * tests/test-mbspcasecmp.c (test_ascii): New function, extracted from
+       main.
+       (test_utf_8): Likewise. Add test cases with incomplete characters.
+       (main): Invoke them. Accept a numeric argument.
+       * tests/test-mbspcasecmp-4.sh: Renamed from tests/test-mbspcasecmp.sh.
+       * tests/test-mbspcasecmp-3.sh: New file, based on
+       tests/test-mbmemcasecmp-3.sh.
+       * modules/mbspcasecmp-tests (Files): Update after rename. Add
+       locale-en.m4, locale-fr.m4.
+       (configure.ac): Invoke gt_LOCALE_EN_UTF8, gt_LOCALE_FR_UTF8.
+       (Makefile.am): Arrange to run test-mbspcasecmp-3.sh,
+       test-mbspcasecmp-4.sh, instead of test-mbspcasecmp.sh.
+
 2026-05-25  Bruno Haible  <bruno@clisp.org>
 
        mbsncasecmp tests: Enhance tests.
index e82a37eb23dde0b6b68675991b8366f3c66fb5dc..4ca8c4d95e965d5f2b900d8d30ed017f7e36aaa8 100644 (file)
@@ -1,7 +1,10 @@
 Files:
-tests/test-mbspcasecmp.sh
+tests/test-mbspcasecmp-3.sh
+tests/test-mbspcasecmp-4.sh
 tests/test-mbspcasecmp.c
 tests/macros.h
+m4/locale-en.m4
+m4/locale-fr.m4
 m4/locale-tr.m4
 m4/codeset.m4
 
@@ -9,10 +12,15 @@ Depends-on:
 setlocale
 
 configure.ac:
+gt_LOCALE_EN_UTF8
+gt_LOCALE_FR_UTF8
 gt_LOCALE_TR_UTF8
 
 Makefile.am:
-TESTS += test-mbspcasecmp.sh
-TESTS_ENVIRONMENT += LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
+TESTS += test-mbspcasecmp-3.sh test-mbspcasecmp-4.sh
+TESTS_ENVIRONMENT += \
+  LOCALE_EN_UTF8='@LOCALE_EN_UTF8@' \
+  LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
+  LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
 check_PROGRAMS += test-mbspcasecmp
 test_mbspcasecmp_LDADD = $(LDADD) $(LIBUNISTRING) $(SETLOCALE_LIB) $(MBRTOWC_LIB) $(LIBC32CONV)
diff --git a/tests/test-mbspcasecmp-3.sh b/tests/test-mbspcasecmp-3.sh
new file mode 100755 (executable)
index 0000000..dc4619a
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# Test whether a specific UTF-8 locale is installed.
+: "${LOCALE_EN_UTF8=en_US.UTF-8}"
+: "${LOCALE_FR_UTF8=fr_FR.UTF-8}"
+if test "$LOCALE_EN_UTF8" = none && test $LOCALE_FR_UTF8 = none; then
+  if test -f /usr/bin/localedef; then
+    echo "Skipping test: no english or french Unicode locale is installed"
+  else
+    echo "Skipping test: no english or french Unicode locale is supported"
+  fi
+  exit 77
+fi
+
+# It's sufficient to test in one of the two locales.
+if test $LOCALE_FR_UTF8 != none; then
+  testlocale=$LOCALE_FR_UTF8
+else
+  testlocale="$LOCALE_EN_UTF8"
+fi
+
+LC_ALL="$testlocale" \
+${CHECKER} ./test-mbspcasecmp${EXEEXT} 3
similarity index 89%
rename from tests/test-mbspcasecmp.sh
rename to tests/test-mbspcasecmp-4.sh
index 1e390755f1b75c6adb82fce9a4a0cec3f59e7494..daef45b62c96833f38da659e519802c1b05d2e39 100755 (executable)
@@ -12,4 +12,4 @@ if test $LOCALE_TR_UTF8 = none; then
 fi
 
 LC_ALL=$LOCALE_TR_UTF8 \
-${CHECKER} ./test-mbspcasecmp${EXEEXT}
+${CHECKER} ./test-mbspcasecmp${EXEEXT} 4
index 8839a7444dc7cac89867b018d6a92c23804eda1e..a1407164cd843110370b804f3209fa5088021ab7 100644 (file)
 
 #include "macros.h"
 
-int
-main ()
+static void
+test_ascii (void)
 {
-  /* configure should already have checked that the locale is supported.  */
-  if (setlocale (LC_ALL, "") == NULL)
-    return 1;
-
   {
     const char string[] = "paragraph";
     ASSERT (mbspcasecmp (string, "Paragraph") == string + 9);
@@ -60,31 +56,109 @@ main ()
     const char string[] = "paragraph";
     ASSERT (mbspcasecmp (string, "para") == string + 4);
   }
+}
 
+static void
+test_utf_8 (bool turkish)
+{
   /* The following tests shows how mbspcasecmp() is different from
      strncasecmp().  */
 
+  if (turkish)
+    {
+      {
+        const char string[] = "\303\266zg\303\274rt\303\274k"; /* özgürtük */
+        ASSERT (mbspcasecmp (string, "\303\226ZG\303\234R") == string + 7); /* özgür */
+      }
+
+      {
+        const char string[] = "\303\226ZG\303\234Rt\303\274k"; /* özgürtük */
+        ASSERT (mbspcasecmp (string, "\303\266zg\303\274r") == string + 7); /* özgür */
+      }
+
+      /* This test shows how strings of different size can compare equal.  */
+
+      {
+        const char string[] = "turkishtime";
+        ASSERT (mbspcasecmp (string, "TURK\304\260SH") == string + 7);
+      }
+
+      {
+        const char string[] = "TURK\304\260SHK\303\234LT\303\234R";
+        ASSERT (mbspcasecmp (string, "turkish") == string + 8);
+      }
+    }
+
+  /* Incomplete characters.  See
+     https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf
+     page 128 table 3-11.  */
+
+  /* "\341\200\240" = 0xE1 0x80 0xA0 = U+1020.  */
   {
-    const char string[] = "\303\266zg\303\274rt\303\274k"; /* özgürtük */
-    ASSERT (mbspcasecmp (string, "\303\226ZG\303\234R") == string + 7); /* özgür */
+    const char string[] = "\341\200";
+    ASSERT (mbspcasecmp (string, "\341\200") == string + 2);
   }
-
   {
-    const char string[] = "\303\226ZG\303\234Rt\303\274k"; /* özgürtük */
-    ASSERT (mbspcasecmp (string, "\303\266zg\303\274r") == string + 7); /* özgür */
+    const char string[] = "\341\200X";
+    ASSERT (mbspcasecmp (string, "\341\200x") == string + 3);
   }
-
-  /* This test shows how strings of different size can compare equal.  */
-
   {
-    const char string[] = "turkishtime";
-    ASSERT (mbspcasecmp (string, "TURK\304\260SH") == string + 7);
+    const char string[] = "\341";
+    ASSERT (mbspcasecmp (string, "\341") == string + 1);
   }
-
   {
-    const char string[] = "TURK\304\260SHK\303\234LT\303\234R";
-    ASSERT (mbspcasecmp (string, "turkish") == string + 8);
+    const char string[] = "\341X";
+    ASSERT (mbspcasecmp (string, "\341x") == string + 2);
   }
+  /* "\360\221\222\240" = 0xF0 0x91 0x92 0xA0 = U+114A0.  */
+  {
+    const char string[] = "\360\221\222";
+    ASSERT (mbspcasecmp (string, "\360\221\222") == string + 3);
+  }
+  {
+    const char string[] = "\360\221\222X";
+    ASSERT (mbspcasecmp (string, "\360\221\222x") == string + 4);
+  }
+  {
+    const char string[] = "\360\221";
+    ASSERT (mbspcasecmp (string, "\360\221") == string + 2);
+  }
+  {
+    const char string[] = "\360\221X";
+    ASSERT (mbspcasecmp (string, "\360\221x") == string + 3);
+  }
+  {
+    const char string[] = "\360";
+    ASSERT (mbspcasecmp (string, "\360") == string + 1);
+  }
+  {
+    const char string[] = "\360X";
+    ASSERT (mbspcasecmp (string, "\360x") == string + 2);
+  }
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  test_ascii ();
+
+  if (argc > 1)
+    switch (argv[1][0])
+      {
+      case '3':
+        /* Locale encoding is UTF-8, locale is not Turkish.  */
+        test_utf_8 (false);
+        return test_exit_status;
+
+      case '4':
+        /* Locale encoding is UTF-8, locale is Turkish.  */
+        test_utf_8 (true);
+        return test_exit_status;
+      }
 
-  return test_exit_status;
+  return 1;
 }