From: Bruno Haible Date: Sun, 16 Feb 2025 17:02:00 +0000 (+0100) Subject: strcasecmp: Add tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc6bec11ffd3761d87e1e4b0c21697a3c6771694;p=thirdparty%2Fgnulib.git strcasecmp: Add tests. * tests/test-strcasecmp-1.sh: New file. * tests/test-strcasecmp-2.sh: New file. * tests/test-strcasecmp.c: New file. * modules/strcasecmp-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index bf5e91746b..052ec74b9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2025-02-16 Bruno Haible + strcasecmp: Add tests. + * tests/test-strcasecmp-1.sh: New file. + * tests/test-strcasecmp-2.sh: New file. + * tests/test-strcasecmp.c: New file. + * modules/strcasecmp-tests: New file. + strcasecmp: Work around Solaris, Cygwin bug. * lib/strings.in.h (strcasecmp): Consider REPLACE_STRCASECMP. Use the usual idioms. diff --git a/modules/strcasecmp-tests b/modules/strcasecmp-tests new file mode 100644 index 0000000000..aeff0381a0 --- /dev/null +++ b/modules/strcasecmp-tests @@ -0,0 +1,21 @@ +Files: +tests/test-strcasecmp-1.sh +tests/test-strcasecmp-2.sh +tests/test-strcasecmp.c +tests/signature.h +tests/macros.h +m4/locale-fr.m4 +m4/codeset.m4 + +Depends-on: +setlocale + +configure.ac: +gt_LOCALE_FR + +Makefile.am: +TESTS += test-strcasecmp-1.sh test-strcasecmp-2.sh +TESTS_ENVIRONMENT += \ + LOCALE_FR='@LOCALE_FR@' +check_PROGRAMS += test-strcasecmp +test_strcasecmp_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/tests/test-strcasecmp-1.sh b/tests/test-strcasecmp-1.sh new file mode 100755 index 0000000000..1a8ad80ac7 --- /dev/null +++ b/tests/test-strcasecmp-1.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Test in the POSIX locale. +LC_ALL=C \ +${CHECKER} ./test-strcasecmp${EXEEXT} 1 || exit 1 +LC_ALL=POSIX \ +${CHECKER} ./test-strcasecmp${EXEEXT} 1 || exit 1 + +exit 0 diff --git a/tests/test-strcasecmp-2.sh b/tests/test-strcasecmp-2.sh new file mode 100755 index 0000000000..b590a7a069 --- /dev/null +++ b/tests/test-strcasecmp-2.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +${CHECKER} ./test-strcasecmp${EXEEXT} 2 diff --git a/tests/test-strcasecmp.c b/tests/test-strcasecmp.c new file mode 100644 index 0000000000..0be6ffaecb --- /dev/null +++ b/tests/test-strcasecmp.c @@ -0,0 +1,73 @@ +/* Test of strcasecmp() function. + Copyright (C) 2008-2025 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (strcasecmp, int, (const char *, const char *)); + +#include +#include + +#include "macros.h" + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + ASSERT (strcasecmp ("paragraph", "Paragraph") == 0); + + ASSERT (strcasecmp ("paragrapH", "parAgRaph") == 0); + + ASSERT (strcasecmp ("paragraph", "paraLyzed") < 0); + ASSERT (strcasecmp ("paraLyzed", "paragraph") > 0); + + ASSERT (strcasecmp ("para", "paragraph") < 0); + ASSERT (strcasecmp ("paragraph", "para") > 0); + + if (argc > 1) + switch (argv[1][0]) + { + case '1': + /* C or POSIX locale. */ + return test_exit_status; + + case '2': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + + /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */ + /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */ + ASSERT (strcasecmp ("Fej\311r", "Fej\351r") == 0); + ASSERT (strcasecmp ("Fej\351r", "Fej\311r") == 0); + ASSERT (strcasecmp ("Fejer", "Fej\311r") < 0); + ASSERT (strcasecmp ("Fej\311r", "Fejer") > 0); + + /* Compare with U+00D7 MULTIPLICATION SIGN */ + ASSERT (strcasecmp ("Fej\311r", "Fej\327") > 0); + ASSERT (strcasecmp ("Fej\327", "Fej\311r") < 0); + ASSERT (strcasecmp ("Fej\351r", "Fej\327") > 0); + ASSERT (strcasecmp ("Fej\327", "Fej\351r") < 0); + + return test_exit_status; + } + + return 1; +}