| 1 |
/* Test of iswpunct() function. |
| 2 |
Copyright (C) 2020-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 <wctype.h> |
| 20 |
|
| 21 |
#include "signature.h" |
| 22 |
SIGNATURE_CHECK (iswpunct, int, (wint_t)); |
| 23 |
|
| 24 |
#include <locale.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
#include <wchar.h> |
| 28 |
|
| 29 |
#include "macros.h" |
| 30 |
|
| 31 |
/* Returns the value of iswpunct for the multibyte character s[0..n-1]. */ |
| 32 |
static int |
| 33 |
for_character (const char *s, size_t n) |
| 34 |
{ |
| 35 |
mbstate_t state; |
| 36 |
wchar_t wc; |
| 37 |
size_t ret; |
| 38 |
|
| 39 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 40 |
wc = (wchar_t) 0xBADFACE; |
| 41 |
ret = mbrtowc (&wc, s, n, &state); |
| 42 |
if (ret == n) |
| 43 |
return iswpunct (wc); |
| 44 |
else |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
int |
| 49 |
main (int argc, char *argv[]) |
| 50 |
{ |
| 51 |
int is; |
| 52 |
char buf[4]; |
| 53 |
|
| 54 |
/* configure should already have checked that the locale is supported. */ |
| 55 |
if (setlocale (LC_ALL, "") == NULL) |
| 56 |
return 1; |
| 57 |
|
| 58 |
/* Test WEOF. */ |
| 59 |
is = iswpunct (WEOF); |
| 60 |
ASSERT (is == 0); |
| 61 |
|
| 62 |
/* Test single-byte characters. |
| 63 |
POSIX specifies in |
| 64 |
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html> |
| 65 |
no explicit list of punctuation or symbol characters. */ |
| 66 |
{ |
| 67 |
int c; |
| 68 |
|
| 69 |
for (c = 0; c < 0x100; c++) |
| 70 |
switch (c) |
| 71 |
{ |
| 72 |
case '\t': case '\v': case '\f': |
| 73 |
case ' ': case '!': case '"': case '#': case '%': |
| 74 |
case '&': case '\'': case '(': case ')': case '*': |
| 75 |
case '+': case ',': case '-': case '.': case '/': |
| 76 |
case '0': case '1': case '2': case '3': case '4': |
| 77 |
case '5': case '6': case '7': case '8': case '9': |
| 78 |
case ':': case ';': case '<': case '=': case '>': |
| 79 |
case '?': |
| 80 |
case 'A': case 'B': case 'C': case 'D': case 'E': |
| 81 |
case 'F': case 'G': case 'H': case 'I': case 'J': |
| 82 |
case 'K': case 'L': case 'M': case 'N': case 'O': |
| 83 |
case 'P': case 'Q': case 'R': case 'S': case 'T': |
| 84 |
case 'U': case 'V': case 'W': case 'X': case 'Y': |
| 85 |
case 'Z': |
| 86 |
case '[': case '\\': case ']': case '^': case '_': |
| 87 |
case 'a': case 'b': case 'c': case 'd': case 'e': |
| 88 |
case 'f': case 'g': case 'h': case 'i': case 'j': |
| 89 |
case 'k': case 'l': case 'm': case 'n': case 'o': |
| 90 |
case 'p': case 'q': case 'r': case 's': case 't': |
| 91 |
case 'u': case 'v': case 'w': case 'x': case 'y': |
| 92 |
case 'z': case '{': case '|': case '}': case '~': |
| 93 |
/* c is in the ISO C "basic character set". */ |
| 94 |
buf[0] = (unsigned char) c; |
| 95 |
is = for_character (buf, 1); |
| 96 |
switch (c) |
| 97 |
{ |
| 98 |
case ' ': |
| 99 |
case '0': case '1': case '2': case '3': case '4': |
| 100 |
case '5': case '6': case '7': case '8': case '9': |
| 101 |
case 'A': case 'B': case 'C': case 'D': case 'E': |
| 102 |
case 'F': case 'G': case 'H': case 'I': case 'J': |
| 103 |
case 'K': case 'L': case 'M': case 'N': case 'O': |
| 104 |
case 'P': case 'Q': case 'R': case 'S': case 'T': |
| 105 |
case 'U': case 'V': case 'W': case 'X': case 'Y': |
| 106 |
case 'Z': |
| 107 |
case 'a': case 'b': case 'c': case 'd': case 'e': |
| 108 |
case 'f': case 'g': case 'h': case 'i': case 'j': |
| 109 |
case 'k': case 'l': case 'm': case 'n': case 'o': |
| 110 |
case 'p': case 'q': case 'r': case 's': case 't': |
| 111 |
case 'u': case 'v': case 'w': case 'x': case 'y': |
| 112 |
case 'z': |
| 113 |
/* c is an alphanumeric or space character. */ |
| 114 |
ASSERT (is == 0); |
| 115 |
break; |
| 116 |
case '!': case '"': case '#': case '%': |
| 117 |
case '&': case '\'': case '(': case ')': case '*': |
| 118 |
case '+': case ',': case '-': case '.': case '/': |
| 119 |
case ':': case ';': case '<': case '=': case '>': |
| 120 |
case '?': |
| 121 |
case '[': case '\\': case ']': case '^': case '_': |
| 122 |
case '{': case '|': case '}': case '~': |
| 123 |
/* These characters are usually expected to be punctuation or |
| 124 |
symbol characters. */ |
| 125 |
ASSERT (is != 0); |
| 126 |
break; |
| 127 |
default: |
| 128 |
ASSERT (is == 0); |
| 129 |
break; |
| 130 |
} |
| 131 |
break; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
if (argc > 1) |
| 136 |
switch (argv[1][0]) |
| 137 |
{ |
| 138 |
case '0': |
| 139 |
/* C locale; tested above. */ |
| 140 |
/* These characters are not in the ISO C "basic character set", but |
| 141 |
are nevertheless usually expected to be punctuation or symbol |
| 142 |
characters. */ |
| 143 |
is = for_character ("$", 1); |
| 144 |
ASSERT (is != 0); |
| 145 |
is = for_character ("@", 1); |
| 146 |
ASSERT (is != 0); |
| 147 |
is = for_character ("`", 1); |
| 148 |
ASSERT (is != 0); |
| 149 |
return test_exit_status; |
| 150 |
} |
| 151 |
|
| 152 |
return 1; |
| 153 |
} |