Debian Codegraph @

gnulib-tests/test-strncasecmp.c

raw
1 /* Test of strncasecmp() 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 (strncasecmp, int, (const char *, const char *, size_t));
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 (strncasecmp ("paragraph", "Paragraph", 9) == 0);
37
38 ASSERT (strncasecmp ("paragrapH", "parAgRaph", 9) == 0);
39
40 ASSERT (strncasecmp ("paragraph", "paraLyzed", 9) < 0);
41 ASSERT (strncasecmp ("paraLyzed", "paragraph", 9) > 0);
42
43 ASSERT (strncasecmp ("para", "paragraph", 9) < 0);
44 ASSERT (strncasecmp ("paragraph", "para", 9) > 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 (strncasecmp ("Fej\311r", "Fej\351r", 5) == 0);
59 ASSERT (strncasecmp ("Fej\351r", "Fej\311r", 5) == 0);
60 ASSERT (strncasecmp ("Fejer", "Fej\311r", 5) < 0);
61 ASSERT (strncasecmp ("Fej\311r", "Fejer", 5) > 0);
62
63 /* Compare with U+00D7 MULTIPLICATION SIGN */
64 ASSERT (strncasecmp ("Fej\311r", "Fej\327", 5) > 0);
65 ASSERT (strncasecmp ("Fej\327", "Fej\311r", 5) < 0);
66 ASSERT (strncasecmp ("Fej\351r", "Fej\327", 5) > 0);
67 ASSERT (strncasecmp ("Fej\327", "Fej\351r", 5) < 0);
68
69 return test_exit_status;
70 }
71
72 return 1;
73 }