From: Bruno Haible Date: Sun, 16 Feb 2025 21:32:37 +0000 (+0100) Subject: strncasecmp_l: Add tests. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=bc89c9cf1efebd9bc7b7524e3f6471e1c367f706;p=gnulib.git strncasecmp_l: Add tests. * tests/test-strncasecmp_l.c: New file. * modules/strncasecmp_l-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index aa5f4dd468..21c1b8a491 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2025-02-16 Bruno Haible + strncasecmp_l: Add tests. + * tests/test-strncasecmp_l.c: New file. + * modules/strncasecmp_l-tests: New file. + strncasecmp_l: New module. * lib/strings.in.h (strncasecmp_l): New declaration. * lib/strncasecmp_l.c: New file, based on lib/strncasecmp.c. diff --git a/modules/strncasecmp_l-tests b/modules/strncasecmp_l-tests new file mode 100644 index 0000000000..909d11701e --- /dev/null +++ b/modules/strncasecmp_l-tests @@ -0,0 +1,16 @@ +Files: +tests/test-strncasecmp_l.c +tests/signature.h +tests/macros.h +m4/musl.m4 + +Depends-on: +newlocale +freelocale + +configure.ac: +gl_MUSL_LIBC + +Makefile.am: +TESTS += test-strncasecmp_l +check_PROGRAMS += test-strncasecmp_l diff --git a/tests/test-strncasecmp_l.c b/tests/test-strncasecmp_l.c new file mode 100644 index 0000000000..a043539fcd --- /dev/null +++ b/tests/test-strncasecmp_l.c @@ -0,0 +1,88 @@ +/* Test of strncasecmp_l() function. + Copyright (C) 2020-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 + +#include "signature.h" +SIGNATURE_CHECK (strncasecmp_l, int, (const char *, const char *, size_t, locale_t)); + +#include + +#include "macros.h" + +static void +test_single_locale_common (locale_t locale) +{ + ASSERT (strncasecmp_l ("paragraph", "Paragraph", 9, locale) == 0); + + ASSERT (strncasecmp_l ("paragrapH", "parAgRaph", 9, locale) == 0); + + ASSERT (strncasecmp_l ("paragraph", "paraLyzed", 9, locale) < 0); + ASSERT (strncasecmp_l ("paraLyzed", "paragraph", 9, locale) > 0); + + ASSERT (strncasecmp_l ("para", "paragraph", 9, locale) < 0); + ASSERT (strncasecmp_l ("paragraph", "para", 9, locale) > 0); +} + +int +main () +{ + { + locale_t locale = newlocale (LC_ALL_MASK, "C", NULL); + ASSERT (locale != NULL); + + test_single_locale_common (locale); + + freelocale (locale); + } +#if !MUSL_LIBC /* musl libc has no unibyte locales */ + { +# if defined _WIN32 && !defined __CYGWIN__ + locale_t locale = newlocale (LC_ALL_MASK, "French_France.1252", NULL); +# else + locale_t locale = newlocale (LC_ALL_MASK, "fr_FR.ISO-8859-1", NULL); + if (locale == NULL) + locale = newlocale (LC_ALL_MASK, "fr_FR.ISO8859-1", NULL); +# endif + if (locale != NULL) + { + test_single_locale_common (locale); + + /* 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 (strncasecmp_l ("Fej\311r", "Fej\351r", 5, locale) == 0); + ASSERT (strncasecmp_l ("Fej\351r", "Fej\311r", 5, locale) == 0); + ASSERT (strncasecmp_l ("Fejer", "Fej\311r", 5, locale) < 0); + ASSERT (strncasecmp_l ("Fej\311r", "Fejer", 5, locale) > 0); + + /* Compare with U+00D7 MULTIPLICATION SIGN */ + ASSERT (strncasecmp_l ("Fej\311r", "Fej\327", 5, locale) > 0); + ASSERT (strncasecmp_l ("Fej\327", "Fej\311r", 5, locale) < 0); + ASSERT (strncasecmp_l ("Fej\351r", "Fej\327", 5, locale) > 0); + ASSERT (strncasecmp_l ("Fej\327", "Fej\351r", 5, locale) < 0); + + freelocale (locale); + } + } +#endif + + return test_exit_status; +}