]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
mbscasecmp tests: Enhance tests.
authorBruno Haible <bruno@clisp.org>
Mon, 25 May 2026 16:20:40 +0000 (18:20 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 25 May 2026 16:20:40 +0000 (18:20 +0200)
* tests/test-mbscasecmp.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-mbscasecmp-4.sh: Renamed from tests/test-mbscasecmp.sh.
* tests/test-mbscasecmp-3.sh: New file, based on
tests/test-mbmemcasecmp-3.sh.
* modules/mbscasecmp-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-mbscasecmp-3.sh,
test-mbscasecmp-4.sh, instead of test-mbscasecmp.sh.

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

index 02ad380e551484b568be2234c854d28b9b4af3ea..5940e0d95f1b426933707cc69a262949ce3bc916 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2026-05-25  Bruno Haible  <bruno@clisp.org>
+
+       mbscasecmp tests: Enhance tests.
+       * tests/test-mbscasecmp.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-mbscasecmp-4.sh: Renamed from tests/test-mbscasecmp.sh.
+       * tests/test-mbscasecmp-3.sh: New file, based on
+       tests/test-mbmemcasecmp-3.sh.
+       * modules/mbscasecmp-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-mbscasecmp-3.sh,
+       test-mbscasecmp-4.sh, instead of test-mbscasecmp.sh.
+
 2026-05-25  Bruno Haible  <bruno@clisp.org>
 
        mbs_endswith tests: Enhance tests.
index 61282af8624ae22c11ac2b1fa0a2142a39f70435..bdbb0cf17b47dac5009c2a142350761a825f10e3 100644 (file)
@@ -1,7 +1,10 @@
 Files:
-tests/test-mbscasecmp.sh
+tests/test-mbscasecmp-3.sh
+tests/test-mbscasecmp-4.sh
 tests/test-mbscasecmp.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-mbscasecmp.sh
-TESTS_ENVIRONMENT += LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
+TESTS += test-mbscasecmp-3.sh test-mbscasecmp-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-mbscasecmp
 test_mbscasecmp_LDADD = $(LDADD) $(LIBUNISTRING) $(SETLOCALE_LIB) $(MBRTOWC_LIB) $(LIBC32CONV)
diff --git a/tests/test-mbscasecmp-3.sh b/tests/test-mbscasecmp-3.sh
new file mode 100755 (executable)
index 0000000..72ee7d4
--- /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-mbscasecmp${EXEEXT} 3
similarity index 89%
rename from tests/test-mbscasecmp.sh
rename to tests/test-mbscasecmp-4.sh
index 73e62b5f50f1cef0f414aac12b683bc960e4df4f..e5c5a90b17e8df022e221d5ea1dc4987b4a08602 100755 (executable)
@@ -12,4 +12,4 @@ if test $LOCALE_TR_UTF8 = none; then
 fi
 
 LC_ALL=$LOCALE_TR_UTF8 \
-${CHECKER} ./test-mbscasecmp${EXEEXT}
+${CHECKER} ./test-mbscasecmp${EXEEXT} 4
index 1c12691deaaa60830b257e0deb0a614875feb0ad..f309d3e517c0220d30e15d0ebd95d109bc5c3d6e 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;
-
   ASSERT (mbscasecmp ("paragraph", "Paragraph") == 0);
 
   ASSERT (mbscasecmp ("paragrapH", "parAgRaph") == 0);
@@ -40,16 +36,64 @@ main ()
 
   ASSERT (mbscasecmp ("para", "paragraph") < 0);
   ASSERT (mbscasecmp ("paragraph", "para") > 0);
+}
 
+static void
+test_utf_8 (bool turkish)
+{
   /* The following tests shows how mbscasecmp() is different from
      strcasecmp().  */
 
-  ASSERT (mbscasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R") == 0); /* özgür */
-  ASSERT (mbscasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r") == 0); /* özgür */
+  if (turkish)
+    {
+      ASSERT (mbscasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R") == 0); /* özgür */
+      ASSERT (mbscasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r") == 0); /* özgür */
+
+      /* This test shows how strings of different size can compare equal.  */
+      ASSERT (mbscasecmp ("turkish", "TURK\304\260SH") == 0);
+      ASSERT (mbscasecmp ("TURK\304\260SH", "turkish") == 0);
+    }
+
+  /* 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.  */
+  ASSERT (mbscasecmp ("\341\200", "\341\200") == 0);
+  ASSERT (mbscasecmp ("\341\200X", "\341\200x") == 0);
+  ASSERT (mbscasecmp ("\341", "\341") == 0);
+  ASSERT (mbscasecmp ("\341X", "\341x") == 0);
+  /* "\360\221\222\240" = 0xF0 0x91 0x92 0xA0 = U+114A0.  */
+  ASSERT (mbscasecmp ("\360\221\222", "\360\221\222") == 0);
+  ASSERT (mbscasecmp ("\360\221\222X", "\360\221\222x") == 0);
+  ASSERT (mbscasecmp ("\360\221", "\360\221") == 0);
+  ASSERT (mbscasecmp ("\360\221X", "\360\221x") == 0);
+  ASSERT (mbscasecmp ("\360", "\360") == 0);
+  ASSERT (mbscasecmp ("\360X", "\360x") == 0);
+}
+
+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;
 
-  /* This test shows how strings of different size can compare equal.  */
-  ASSERT (mbscasecmp ("turkish", "TURK\304\260SH") == 0);
-  ASSERT (mbscasecmp ("TURK\304\260SH", "turkish") == 0);
+      case '4':
+        /* Locale encoding is UTF-8, locale is Turkish.  */
+        test_utf_8 (true);
+        return test_exit_status;
+      }
 
-  return test_exit_status;
+  return 1;
 }