From 9b269e666a57079664969c40ef99599e1e98482b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 16 Feb 2025 22:32:19 +0100 Subject: [PATCH] strcasecmp_l: Add tests. * tests/test-strcasecmp_l.c: New file. * modules/strcasecmp_l-tests: New file. --- ChangeLog | 4 ++ modules/strcasecmp_l-tests | 16 +++++++ tests/test-strcasecmp_l.c | 88 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 modules/strcasecmp_l-tests create mode 100644 tests/test-strcasecmp_l.c diff --git a/ChangeLog b/ChangeLog index 0ffa42d3e7..a8731ea5ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2025-02-16 Bruno Haible + strcasecmp_l: Add tests. + * tests/test-strcasecmp_l.c: New file. + * modules/strcasecmp_l-tests: New file. + strcasecmp_l: New module. * lib/strings.in.h: Include . (strcasecmp_l): New declaration. diff --git a/modules/strcasecmp_l-tests b/modules/strcasecmp_l-tests new file mode 100644 index 0000000000..b096df6fb8 --- /dev/null +++ b/modules/strcasecmp_l-tests @@ -0,0 +1,16 @@ +Files: +tests/test-strcasecmp_l.c +tests/signature.h +tests/macros.h +m4/musl.m4 + +Depends-on: +newlocale +freelocale + +configure.ac: +gl_MUSL_LIBC + +Makefile.am: +TESTS += test-strcasecmp_l +check_PROGRAMS += test-strcasecmp_l diff --git a/tests/test-strcasecmp_l.c b/tests/test-strcasecmp_l.c new file mode 100644 index 0000000000..6202634c4d --- /dev/null +++ b/tests/test-strcasecmp_l.c @@ -0,0 +1,88 @@ +/* Test of strcasecmp_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 (strcasecmp_l, int, (const char *, const char *, locale_t)); + +#include + +#include "macros.h" + +static void +test_single_locale_common (locale_t locale) +{ + ASSERT (strcasecmp_l ("paragraph", "Paragraph", locale) == 0); + + ASSERT (strcasecmp_l ("paragrapH", "parAgRaph", locale) == 0); + + ASSERT (strcasecmp_l ("paragraph", "paraLyzed", locale) < 0); + ASSERT (strcasecmp_l ("paraLyzed", "paragraph", locale) > 0); + + ASSERT (strcasecmp_l ("para", "paragraph", locale) < 0); + ASSERT (strcasecmp_l ("paragraph", "para", 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 (strcasecmp_l ("Fej\311r", "Fej\351r", locale) == 0); + ASSERT (strcasecmp_l ("Fej\351r", "Fej\311r", locale) == 0); + ASSERT (strcasecmp_l ("Fejer", "Fej\311r", locale) < 0); + ASSERT (strcasecmp_l ("Fej\311r", "Fejer", locale) > 0); + + /* Compare with U+00D7 MULTIPLICATION SIGN */ + ASSERT (strcasecmp_l ("Fej\311r", "Fej\327", locale) > 0); + ASSERT (strcasecmp_l ("Fej\327", "Fej\311r", locale) < 0); + ASSERT (strcasecmp_l ("Fej\351r", "Fej\327", locale) > 0); + ASSERT (strcasecmp_l ("Fej\327", "Fej\351r", locale) < 0); + + freelocale (locale); + } + } +#endif + + return test_exit_status; +} -- 2.39.5