openat: don’t close (-1)
[gnulib.git] / tests / test-mbsncasecmp.c
blobce5c3c91b48917f2d603359c5f878d878f7226ab
1 /* Test of case-insensitive string comparison function.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include <config.h>
21 #include <string.h>
23 #include <locale.h>
25 #include "macros.h"
27 int
28 main ()
30 /* configure should already have checked that the locale is supported. */
31 if (setlocale (LC_ALL, "") == NULL)
32 return 1;
34 ASSERT (mbsncasecmp ("paragraph", "Paragraph", 1000000) == 0);
35 ASSERT (mbsncasecmp ("paragraph", "Paragraph", 9) == 0);
37 ASSERT (mbsncasecmp ("paragrapH", "parAgRaph", 1000000) == 0);
38 ASSERT (mbsncasecmp ("paragrapH", "parAgRaph", 9) == 0);
40 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 10) < 0);
41 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 9) < 0);
42 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 5) < 0);
43 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 4) == 0);
44 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 10) > 0);
45 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 9) > 0);
46 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 5) > 0);
47 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 4) == 0);
49 ASSERT (mbsncasecmp ("para", "paragraph", 10) < 0);
50 ASSERT (mbsncasecmp ("para", "paragraph", 9) < 0);
51 ASSERT (mbsncasecmp ("para", "paragraph", 5) < 0);
52 ASSERT (mbsncasecmp ("para", "paragraph", 4) == 0);
53 ASSERT (mbsncasecmp ("paragraph", "para", 10) > 0);
54 ASSERT (mbsncasecmp ("paragraph", "para", 9) > 0);
55 ASSERT (mbsncasecmp ("paragraph", "para", 5) > 0);
56 ASSERT (mbsncasecmp ("paragraph", "para", 4) == 0);
58 /* The following tests shows how mbsncasecmp() is different from
59 strncasecmp(). */
61 ASSERT (mbsncasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R", 99) == 0); /* özgür */
62 ASSERT (mbsncasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r", 99) == 0); /* özgür */
64 /* This test shows how strings of different size can compare equal. */
65 ASSERT (mbsncasecmp ("turkish", "TURK\304\260SH", 7) == 0);
66 ASSERT (mbsncasecmp ("TURK\304\260SH", "turkish", 7) == 0);
68 return test_exit_status;