annotate tests/test-mbspbrk.c @ 17921:58c1b50299a6

getopt: give accurate ambiguity diagnostic on mem exhaustion * lib/getopt.c (_getopt_internal_r): The previous commit broke out the loop too early, which could give a false indication of ambiguous options under memory exhaustion.
author Pádraig Brady <P@draigBrady.com>
date Wed, 18 Feb 2015 22:37:31 +0000
parents ab58d4870664
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of searching a string for a character among a given set of characters.
17848
ab58d4870664 version-etc: new year
Paul Eggert <eggert@cs.ucla.edu>
parents: 17587
diff changeset
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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.
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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/>. */
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
19 #include <config.h>
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <string.h>
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <locale.h>
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
25 #include "macros.h"
8139
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 int
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 main ()
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 {
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* configure should already have checked that the locale is supported. */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (setlocale (LC_ALL, "") == NULL)
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 return 1;
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 ASSERT (mbspbrk ("Some text", "") == NULL);
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 const char input[] = "A long sentence";
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 ASSERT (mbspbrk (input, "aeiou") == input + 3);
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 ASSERT (mbspbrk (input, "iI") == NULL);
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 }
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* The following tests shows how mbspbrk() is different from strpbrk(). */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 {
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 const char input[] = "B\303\266se B\303\274bchen"; /* "Böse Bübchen" */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 ASSERT (mbspbrk (input, "\303\244\303\274") == input + 7); /* "äü" */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 {
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 const char input[] = "B\303\266se B\303\274bchen"; /* "Böse Bübchen" */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (mbspbrk (input, "\303") == NULL); /* invalid multibyte sequence */
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 }
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 return 0;
e8c69f00de52 Tests for module 'mbspbrk'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 }