Debian Codegraph @

gnulib-tests/test-strcasecmp.c

raw
1 /* Test of strcasecmp() function.
2 Copyright (C) 2008-2025 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <strings.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (strcasecmp, int, (const char *, const char *));
23
24 #include <locale.h>
25 #include <stdlib.h>
26
27 #include "macros.h"
28
29 int
30 main (int argc, char *argv[])
31 {
32 /* configure should already have checked that the locale is supported. */
33 if (setlocale (LC_ALL, "") == NULL)
34 return 1;
35
36 ASSERT (strcasecmp ("paragraph", "Paragraph") == 0);
37
38 ASSERT (strcasecmp ("paragrapH", "parAgRaph") == 0);
39
40 ASSERT (strcasecmp ("paragraph", "paraLyzed") < 0);
41 ASSERT (strcasecmp ("paraLyzed", "paragraph") > 0);
42
43 ASSERT (strcasecmp ("para", "paragraph") < 0);
44 ASSERT (strcasecmp ("paragraph", "para") > 0);
45
46 if (argc > 1)
47 switch (argv[1][0])
48 {
49 case '1':
50 /* C or POSIX locale. */
51 return test_exit_status;
52
53 case '2':
54 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
55
56 /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
57 /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
58 ASSERT (strcasecmp ("Fej\311r", "Fej\351r") == 0);
59 ASSERT (strcasecmp ("Fej\351r", "Fej\311r") == 0);
60 ASSERT (strcasecmp ("Fejer", "Fej\311r") < 0);
61 ASSERT (strcasecmp ("Fej\311r", "Fejer") > 0);
62
63 /* Compare with U+00D7 MULTIPLICATION SIGN */
64 ASSERT (strcasecmp ("Fej\311r", "Fej\327") > 0);
65 ASSERT (strcasecmp ("Fej\327", "Fej\311r") < 0);
66 ASSERT (strcasecmp ("Fej\351r", "Fej\327") > 0);
67 ASSERT (strcasecmp ("Fej\327", "Fej\351r") < 0);
68
69 return test_exit_status;
70 }
71
72 return 1;
73 }