0005-ctype.c (10103B)
1 #define __USE_MACROS 2 #include <assert.h> 3 #include <ctype.h> 4 #include <stdio.h> 5 #include <limits.h> 6 7 /* 8 * This test assumes an ascii representation 9 */ 10 11 #define TESTW(f) fputs(#f ":" , stdout); \ 12 for (i = 0; i <= UCHAR_MAX; i++) \ 13 if (f(i)) printf(" %d", i); \ 14 putchar('\n') 15 16 #define TESTC(f) fputs(#f ": " , stdout); \ 17 for (i = 0; i <= UCHAR_MAX; i++) \ 18 if (f(i)) putchar(i); \ 19 putchar('\n') 20 21 #define TESTEOF(f) fputs(#f ": " , stdout); \ 22 if (!f(EOF)) putchar('!'); puts("EOF"); 23 24 #define TESTLU(f) \ 25 for (i = 0; i < UCHAR_MAX; i++) { \ 26 n = f(i); \ 27 if (!isgraph(i)) \ 28 continue; \ 29 printf("%s: %c <-> %c\n", #f, i, n); \ 30 } 31 32 void 33 test1() 34 { 35 int i; 36 37 puts("\ntest1"); 38 TESTC(isalnum); 39 TESTC(isalpha); 40 TESTC(isdigit); 41 TESTC(isgraph); 42 TESTC(islower); 43 TESTC(isupper); 44 TESTC(isprint); 45 TESTC(ispunct); 46 TESTC(isxdigit); 47 TESTC(isdigit); 48 TESTW(iscntrl); 49 TESTW(isspace); 50 TESTEOF(isalpha); 51 TESTEOF(isdigit); 52 TESTEOF(isgraph); 53 TESTEOF(islower); 54 TESTEOF(isupper); 55 TESTEOF(isprint); 56 TESTEOF(ispunct); 57 TESTEOF(isxdigit); 58 TESTEOF(isdigit); 59 TESTEOF(iscntrl); 60 TESTEOF(isspace); 61 } 62 63 #undef isalnum 64 #undef isalpha 65 #undef isdigit 66 #undef isgraph 67 #undef islower 68 #undef isupper 69 #undef isprint 70 #undef ispunct 71 #undef isxdigit 72 #undef isdigit 73 74 void 75 test2() 76 { 77 int i; 78 79 puts("\ntest2"); 80 TESTC(isalnum); 81 TESTC(isalpha); 82 TESTC(isdigit); 83 TESTC(isgraph); 84 TESTC(islower); 85 TESTC(isupper); 86 TESTC(isprint); 87 TESTC(ispunct); 88 TESTC(isxdigit); 89 TESTC(isdigit); 90 TESTW(iscntrl); 91 TESTW(isspace); 92 TESTEOF(isalpha); 93 TESTEOF(isdigit); 94 TESTEOF(isgraph); 95 TESTEOF(islower); 96 TESTEOF(isupper); 97 TESTEOF(isprint); 98 TESTEOF(ispunct); 99 TESTEOF(isxdigit); 100 TESTEOF(isdigit); 101 TESTEOF(iscntrl); 102 TESTEOF(isspace); 103 } 104 105 void test3() 106 { 107 int i, n; 108 109 puts("\ntest3"); 110 TESTLU(tolower); 111 TESTLU(toupper); 112 } 113 114 #undef tolower 115 #undef toupper 116 117 void test4() 118 { 119 int i, n; 120 121 puts("\ntest4"); 122 TESTLU(tolower); 123 TESTLU(toupper); 124 assert(tolower(EOF) == EOF); 125 assert(toupper(EOF) == EOF); 126 } 127 128 int 129 main() 130 { 131 test1(); 132 test2(); 133 test3(); 134 test4(); 135 136 return 0; 137 } 138 139 /* 140 output: 141 142 test1 143 isalnum: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 144 isalpha: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 145 isdigit: 0123456789 146 isgraph: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 147 islower: abcdefghijklmnopqrstuvwxyz 148 isupper: ABCDEFGHIJKLMNOPQRSTUVWXYZ 149 isprint: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 150 ispunct: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 151 isxdigit: 0123456789ABCDEFabcdef 152 isdigit: 0123456789 153 iscntrl: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 127 154 isspace: 9 10 11 12 13 32 155 isalpha: !EOF 156 isdigit: !EOF 157 isgraph: !EOF 158 islower: !EOF 159 isupper: !EOF 160 isprint: !EOF 161 ispunct: !EOF 162 isxdigit: !EOF 163 isdigit: !EOF 164 iscntrl: !EOF 165 isspace: !EOF 166 167 test2 168 isalnum: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 169 isalpha: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 170 isdigit: 0123456789 171 isgraph: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 172 islower: abcdefghijklmnopqrstuvwxyz 173 isupper: ABCDEFGHIJKLMNOPQRSTUVWXYZ 174 isprint: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 175 ispunct: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 176 isxdigit: 0123456789ABCDEFabcdef 177 isdigit: 0123456789 178 iscntrl: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 127 179 isspace: 9 10 11 12 13 32 180 isalpha: !EOF 181 isdigit: !EOF 182 isgraph: !EOF 183 islower: !EOF 184 isupper: !EOF 185 isprint: !EOF 186 ispunct: !EOF 187 isxdigit: !EOF 188 isdigit: !EOF 189 iscntrl: !EOF 190 isspace: !EOF 191 192 test3 193 tolower: ! <-> ! 194 tolower: " <-> " 195 tolower: # <-> # 196 tolower: $ <-> $ 197 tolower: % <-> % 198 tolower: & <-> & 199 tolower: ' <-> ' 200 tolower: ( <-> ( 201 tolower: ) <-> ) 202 tolower: * <-> * 203 tolower: + <-> + 204 tolower: , <-> , 205 tolower: - <-> - 206 tolower: . <-> . 207 tolower: / <-> / 208 tolower: 0 <-> 0 209 tolower: 1 <-> 1 210 tolower: 2 <-> 2 211 tolower: 3 <-> 3 212 tolower: 4 <-> 4 213 tolower: 5 <-> 5 214 tolower: 6 <-> 6 215 tolower: 7 <-> 7 216 tolower: 8 <-> 8 217 tolower: 9 <-> 9 218 tolower: : <-> : 219 tolower: ; <-> ; 220 tolower: < <-> < 221 tolower: = <-> = 222 tolower: > <-> > 223 tolower: ? <-> ? 224 tolower: @ <-> @ 225 tolower: A <-> a 226 tolower: B <-> b 227 tolower: C <-> c 228 tolower: D <-> d 229 tolower: E <-> e 230 tolower: F <-> f 231 tolower: G <-> g 232 tolower: H <-> h 233 tolower: I <-> i 234 tolower: J <-> j 235 tolower: K <-> k 236 tolower: L <-> l 237 tolower: M <-> m 238 tolower: N <-> n 239 tolower: O <-> o 240 tolower: P <-> p 241 tolower: Q <-> q 242 tolower: R <-> r 243 tolower: S <-> s 244 tolower: T <-> t 245 tolower: U <-> u 246 tolower: V <-> v 247 tolower: W <-> w 248 tolower: X <-> x 249 tolower: Y <-> y 250 tolower: Z <-> z 251 tolower: [ <-> [ 252 tolower: \ <-> \ 253 tolower: ] <-> ] 254 tolower: ^ <-> ^ 255 tolower: _ <-> _ 256 tolower: ` <-> ` 257 tolower: a <-> a 258 tolower: b <-> b 259 tolower: c <-> c 260 tolower: d <-> d 261 tolower: e <-> e 262 tolower: f <-> f 263 tolower: g <-> g 264 tolower: h <-> h 265 tolower: i <-> i 266 tolower: j <-> j 267 tolower: k <-> k 268 tolower: l <-> l 269 tolower: m <-> m 270 tolower: n <-> n 271 tolower: o <-> o 272 tolower: p <-> p 273 tolower: q <-> q 274 tolower: r <-> r 275 tolower: s <-> s 276 tolower: t <-> t 277 tolower: u <-> u 278 tolower: v <-> v 279 tolower: w <-> w 280 tolower: x <-> x 281 tolower: y <-> y 282 tolower: z <-> z 283 tolower: { <-> { 284 tolower: | <-> | 285 tolower: } <-> } 286 tolower: ~ <-> ~ 287 toupper: ! <-> ! 288 toupper: " <-> " 289 toupper: # <-> # 290 toupper: $ <-> $ 291 toupper: % <-> % 292 toupper: & <-> & 293 toupper: ' <-> ' 294 toupper: ( <-> ( 295 toupper: ) <-> ) 296 toupper: * <-> * 297 toupper: + <-> + 298 toupper: , <-> , 299 toupper: - <-> - 300 toupper: . <-> . 301 toupper: / <-> / 302 toupper: 0 <-> 0 303 toupper: 1 <-> 1 304 toupper: 2 <-> 2 305 toupper: 3 <-> 3 306 toupper: 4 <-> 4 307 toupper: 5 <-> 5 308 toupper: 6 <-> 6 309 toupper: 7 <-> 7 310 toupper: 8 <-> 8 311 toupper: 9 <-> 9 312 toupper: : <-> : 313 toupper: ; <-> ; 314 toupper: < <-> < 315 toupper: = <-> = 316 toupper: > <-> > 317 toupper: ? <-> ? 318 toupper: @ <-> @ 319 toupper: A <-> A 320 toupper: B <-> B 321 toupper: C <-> C 322 toupper: D <-> D 323 toupper: E <-> E 324 toupper: F <-> F 325 toupper: G <-> G 326 toupper: H <-> H 327 toupper: I <-> I 328 toupper: J <-> J 329 toupper: K <-> K 330 toupper: L <-> L 331 toupper: M <-> M 332 toupper: N <-> N 333 toupper: O <-> O 334 toupper: P <-> P 335 toupper: Q <-> Q 336 toupper: R <-> R 337 toupper: S <-> S 338 toupper: T <-> T 339 toupper: U <-> U 340 toupper: V <-> V 341 toupper: W <-> W 342 toupper: X <-> X 343 toupper: Y <-> Y 344 toupper: Z <-> Z 345 toupper: [ <-> [ 346 toupper: \ <-> \ 347 toupper: ] <-> ] 348 toupper: ^ <-> ^ 349 toupper: _ <-> _ 350 toupper: ` <-> ` 351 toupper: a <-> A 352 toupper: b <-> B 353 toupper: c <-> C 354 toupper: d <-> D 355 toupper: e <-> E 356 toupper: f <-> F 357 toupper: g <-> G 358 toupper: h <-> H 359 toupper: i <-> I 360 toupper: j <-> J 361 toupper: k <-> K 362 toupper: l <-> L 363 toupper: m <-> M 364 toupper: n <-> N 365 toupper: o <-> O 366 toupper: p <-> P 367 toupper: q <-> Q 368 toupper: r <-> R 369 toupper: s <-> S 370 toupper: t <-> T 371 toupper: u <-> U 372 toupper: v <-> V 373 toupper: w <-> W 374 toupper: x <-> X 375 toupper: y <-> Y 376 toupper: z <-> Z 377 toupper: { <-> { 378 toupper: | <-> | 379 toupper: } <-> } 380 toupper: ~ <-> ~ 381 382 test4 383 tolower: ! <-> ! 384 tolower: " <-> " 385 tolower: # <-> # 386 tolower: $ <-> $ 387 tolower: % <-> % 388 tolower: & <-> & 389 tolower: ' <-> ' 390 tolower: ( <-> ( 391 tolower: ) <-> ) 392 tolower: * <-> * 393 tolower: + <-> + 394 tolower: , <-> , 395 tolower: - <-> - 396 tolower: . <-> . 397 tolower: / <-> / 398 tolower: 0 <-> 0 399 tolower: 1 <-> 1 400 tolower: 2 <-> 2 401 tolower: 3 <-> 3 402 tolower: 4 <-> 4 403 tolower: 5 <-> 5 404 tolower: 6 <-> 6 405 tolower: 7 <-> 7 406 tolower: 8 <-> 8 407 tolower: 9 <-> 9 408 tolower: : <-> : 409 tolower: ; <-> ; 410 tolower: < <-> < 411 tolower: = <-> = 412 tolower: > <-> > 413 tolower: ? <-> ? 414 tolower: @ <-> @ 415 tolower: A <-> a 416 tolower: B <-> b 417 tolower: C <-> c 418 tolower: D <-> d 419 tolower: E <-> e 420 tolower: F <-> f 421 tolower: G <-> g 422 tolower: H <-> h 423 tolower: I <-> i 424 tolower: J <-> j 425 tolower: K <-> k 426 tolower: L <-> l 427 tolower: M <-> m 428 tolower: N <-> n 429 tolower: O <-> o 430 tolower: P <-> p 431 tolower: Q <-> q 432 tolower: R <-> r 433 tolower: S <-> s 434 tolower: T <-> t 435 tolower: U <-> u 436 tolower: V <-> v 437 tolower: W <-> w 438 tolower: X <-> x 439 tolower: Y <-> y 440 tolower: Z <-> z 441 tolower: [ <-> [ 442 tolower: \ <-> \ 443 tolower: ] <-> ] 444 tolower: ^ <-> ^ 445 tolower: _ <-> _ 446 tolower: ` <-> ` 447 tolower: a <-> a 448 tolower: b <-> b 449 tolower: c <-> c 450 tolower: d <-> d 451 tolower: e <-> e 452 tolower: f <-> f 453 tolower: g <-> g 454 tolower: h <-> h 455 tolower: i <-> i 456 tolower: j <-> j 457 tolower: k <-> k 458 tolower: l <-> l 459 tolower: m <-> m 460 tolower: n <-> n 461 tolower: o <-> o 462 tolower: p <-> p 463 tolower: q <-> q 464 tolower: r <-> r 465 tolower: s <-> s 466 tolower: t <-> t 467 tolower: u <-> u 468 tolower: v <-> v 469 tolower: w <-> w 470 tolower: x <-> x 471 tolower: y <-> y 472 tolower: z <-> z 473 tolower: { <-> { 474 tolower: | <-> | 475 tolower: } <-> } 476 tolower: ~ <-> ~ 477 toupper: ! <-> ! 478 toupper: " <-> " 479 toupper: # <-> # 480 toupper: $ <-> $ 481 toupper: % <-> % 482 toupper: & <-> & 483 toupper: ' <-> ' 484 toupper: ( <-> ( 485 toupper: ) <-> ) 486 toupper: * <-> * 487 toupper: + <-> + 488 toupper: , <-> , 489 toupper: - <-> - 490 toupper: . <-> . 491 toupper: / <-> / 492 toupper: 0 <-> 0 493 toupper: 1 <-> 1 494 toupper: 2 <-> 2 495 toupper: 3 <-> 3 496 toupper: 4 <-> 4 497 toupper: 5 <-> 5 498 toupper: 6 <-> 6 499 toupper: 7 <-> 7 500 toupper: 8 <-> 8 501 toupper: 9 <-> 9 502 toupper: : <-> : 503 toupper: ; <-> ; 504 toupper: < <-> < 505 toupper: = <-> = 506 toupper: > <-> > 507 toupper: ? <-> ? 508 toupper: @ <-> @ 509 toupper: A <-> A 510 toupper: B <-> B 511 toupper: C <-> C 512 toupper: D <-> D 513 toupper: E <-> E 514 toupper: F <-> F 515 toupper: G <-> G 516 toupper: H <-> H 517 toupper: I <-> I 518 toupper: J <-> J 519 toupper: K <-> K 520 toupper: L <-> L 521 toupper: M <-> M 522 toupper: N <-> N 523 toupper: O <-> O 524 toupper: P <-> P 525 toupper: Q <-> Q 526 toupper: R <-> R 527 toupper: S <-> S 528 toupper: T <-> T 529 toupper: U <-> U 530 toupper: V <-> V 531 toupper: W <-> W 532 toupper: X <-> X 533 toupper: Y <-> Y 534 toupper: Z <-> Z 535 toupper: [ <-> [ 536 toupper: \ <-> \ 537 toupper: ] <-> ] 538 toupper: ^ <-> ^ 539 toupper: _ <-> _ 540 toupper: ` <-> ` 541 toupper: a <-> A 542 toupper: b <-> B 543 toupper: c <-> C 544 toupper: d <-> D 545 toupper: e <-> E 546 toupper: f <-> F 547 toupper: g <-> G 548 toupper: h <-> H 549 toupper: i <-> I 550 toupper: j <-> J 551 toupper: k <-> K 552 toupper: l <-> L 553 toupper: m <-> M 554 toupper: n <-> N 555 toupper: o <-> O 556 toupper: p <-> P 557 toupper: q <-> Q 558 toupper: r <-> R 559 toupper: s <-> S 560 toupper: t <-> T 561 toupper: u <-> U 562 toupper: v <-> V 563 toupper: w <-> W 564 toupper: x <-> X 565 toupper: y <-> Y 566 toupper: z <-> Z 567 toupper: { <-> { 568 toupper: | <-> | 569 toupper: } <-> } 570 toupper: ~ <-> ~ 571 end: 572 */