Mercurial > hg > octave-nkf > gnulib-hg
annotate tests/test-mbsncasecmp.c @ 9889:0be6f1ab456d
Flush the standard error stream before aborting.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 11 Apr 2008 16:31:39 +0200 |
parents | bbbbbf4cd1c5 |
children | e8d2c6fc33ad |
rev | line source |
---|---|
8157 | 1 /* Test of case-insensitive string comparison function. |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. |
8157 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8157 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
7 (at your option) any later version. |
8157 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8891
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8157 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
8891
633babea5f62
Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents:
8754
diff
changeset
|
19 #include <config.h> |
8157 | 20 |
21 #include <string.h> | |
22 | |
23 #include <locale.h> | |
8754 | 24 #include <stdio.h> |
8157 | 25 #include <stdlib.h> |
26 | |
8754 | 27 #define ASSERT(expr) \ |
28 do \ | |
29 { \ | |
30 if (!(expr)) \ | |
31 { \ | |
32 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ | |
9889
0be6f1ab456d
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
33 fflush (stderr); \ |
8754 | 34 abort (); \ |
35 } \ | |
36 } \ | |
37 while (0) | |
8157 | 38 |
39 int | |
40 main () | |
41 { | |
42 /* configure should already have checked that the locale is supported. */ | |
43 if (setlocale (LC_ALL, "") == NULL) | |
44 return 1; | |
45 | |
46 ASSERT (mbsncasecmp ("paragraph", "Paragraph", 1000000) == 0); | |
47 ASSERT (mbsncasecmp ("paragraph", "Paragraph", 9) == 0); | |
48 | |
49 ASSERT (mbsncasecmp ("paragrapH", "parAgRaph", 1000000) == 0); | |
50 ASSERT (mbsncasecmp ("paragrapH", "parAgRaph", 9) == 0); | |
51 | |
52 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 10) < 0); | |
53 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 9) < 0); | |
54 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 5) < 0); | |
55 ASSERT (mbsncasecmp ("paragraph", "paraLyzed", 4) == 0); | |
56 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 10) > 0); | |
57 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 9) > 0); | |
58 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 5) > 0); | |
59 ASSERT (mbsncasecmp ("paraLyzed", "paragraph", 4) == 0); | |
60 | |
61 ASSERT (mbsncasecmp ("para", "paragraph", 10) < 0); | |
62 ASSERT (mbsncasecmp ("para", "paragraph", 9) < 0); | |
63 ASSERT (mbsncasecmp ("para", "paragraph", 5) < 0); | |
64 ASSERT (mbsncasecmp ("para", "paragraph", 4) == 0); | |
65 ASSERT (mbsncasecmp ("paragraph", "para", 10) > 0); | |
66 ASSERT (mbsncasecmp ("paragraph", "para", 9) > 0); | |
67 ASSERT (mbsncasecmp ("paragraph", "para", 5) > 0); | |
68 ASSERT (mbsncasecmp ("paragraph", "para", 4) == 0); | |
69 | |
70 /* The following tests shows how mbsncasecmp() is different from | |
71 strncasecmp(). */ | |
72 | |
73 ASSERT (mbsncasecmp ("\303\266zg\303\274r", "\303\226ZG\303\234R", 99) == 0); /* özgür */ | |
74 ASSERT (mbsncasecmp ("\303\226ZG\303\234R", "\303\266zg\303\274r", 99) == 0); /* özgür */ | |
75 | |
76 /* This test shows how strings of different size can compare equal. */ | |
77 ASSERT (mbsncasecmp ("turkish", "TURK\304\260SH", 7) == 0); | |
78 ASSERT (mbsncasecmp ("TURK\304\260SH", "turkish", 7) == 0); | |
79 | |
80 return 0; | |
81 } |