Changeset 561 in openpam
- Timestamp:
- 04/02/12 22:17:55 (14 months ago)
- File:
-
- 1 edited
-
trunk/t/t_openpam_readword.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/t/t_openpam_readword.c
r557 r561 28 28 */ 29 29 30 #ifdef HAVE_CONFIG_H 31 # include "config.h" 32 #endif 33 30 34 #include <err.h> 31 35 #include <errno.h> … … 118 122 } 119 123 if (lineno != lines) { 120 t_verbose("expected to advance %d lines, advanced %d lines\n"); 124 t_verbose("expected to advance %d lines, advanced %d lines\n", 125 lines, lineno); 121 126 return (0); 122 127 } … … 154 159 if (fclose(f) != 0) 155 160 err(1, "%s(): %s", __func__, filename); 161 f = NULL; 156 162 } 157 163 … … 347 353 348 354 /*************************************************************************** 349 * Complex cases 350 */ 355 * Escapes 356 */ 357 358 T_FUNC(naked_escape, "naked escape") 359 { 360 int ret; 361 362 orw_open(); 363 orw_output("\\"); 364 orw_rewind(); 365 ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 366 orw_close(); 367 return (ret); 368 } 369 370 T_FUNC(escaped_escape, "escaped escape") 371 { 372 int ret; 373 374 orw_open(); 375 orw_output("\\\\\n"); 376 orw_rewind(); 377 ret = orw_expect("\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 378 orw_close(); 379 return (ret); 380 } 381 382 T_FUNC(escaped_whitespace, "escape whitespace") 383 { 384 int ret; 385 386 orw_open(); 387 orw_output("\\ \\\t \\\r \\\n"); 388 orw_rewind(); 389 ret = orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 390 orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 391 orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 392 orw_expect("\n", 1 /*lines*/, 1 /*eof*/, 0 /*eol*/); 393 orw_close(); 394 return (ret); 395 } 396 397 T_FUNC(escaped_letter, "escaped letter") 398 { 399 int ret; 400 401 orw_open(); 402 orw_output("\\a\n"); 403 orw_rewind(); 404 ret = orw_expect("a", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 405 orw_close(); 406 return (ret); 407 } 408 409 410 411 /*************************************************************************** 412 * Quotes 413 */ 414 415 T_FUNC(naked_single_quote, "naked single quote") 416 { 417 int ret; 418 419 orw_open(); 420 orw_output("'"); 421 orw_rewind(); 422 ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 423 orw_close(); 424 return (ret); 425 } 426 427 T_FUNC(naked_double_quote, "naked double quote") 428 { 429 int ret; 430 431 orw_open(); 432 orw_output("\""); 433 orw_rewind(); 434 ret = orw_expect(NULL, 0 /*lines*/, 1 /*eof*/, 0 /*eol*/); 435 orw_close(); 436 return (ret); 437 } 351 438 352 439 T_FUNC(empty_single_quotes, "empty single quotes") … … 374 461 } 375 462 376 377 463 T_FUNC(quotes_within_quotes, "quotes within quotes") 464 { 465 int ret; 466 467 orw_open(); 468 orw_output("'\"' \"'\"\n"); 469 orw_rewind(); 470 ret = orw_expect("\"", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 471 orw_expect("'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 472 orw_close(); 473 return (ret); 474 } 475 476 T_FUNC(quoted_whitespace, "quoted whitespace") 477 { 478 int ret; 479 480 orw_open(); 481 orw_output("' ' '\t' '\r' '\n' \" \" \"\t\" \"\r\" \"\n\"\n"); 482 orw_rewind(); 483 ret = orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 484 orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 485 orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 486 orw_expect("\n", 1 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 487 orw_expect(" ", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 488 orw_expect("\t", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 489 orw_expect("\r", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 490 orw_expect("\n", 1 /*lines*/, 0 /*eof*/, 1 /*eol*/); 491 orw_close(); 492 return (ret); 493 } 494 495 T_FUNC(quoted_words, "quoted words") 496 { 497 int ret; 498 499 orw_open(); 500 orw_output("'hello' \"world\"\n"); 501 orw_rewind(); 502 ret = orw_expect("hello", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 503 orw_expect("world", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 504 orw_close(); 505 return (ret); 506 } 507 508 509 510 /*************************************************************************** 511 * Combinations of escape and quotes 512 */ 513 514 T_FUNC(escaped_quotes, "escaped quotes") 515 { 516 int ret; 517 518 orw_open(); 519 orw_output("\\\" \\'\n"); 520 orw_rewind(); 521 ret = orw_expect("\"", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 522 orw_expect("'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 523 orw_close(); 524 return (ret); 525 } 526 527 T_FUNC(escaped_letters_within_quotes, "escaped letters within quotes") 528 { 529 int ret; 530 531 orw_open(); 532 orw_output("\"\\a\" '\\a'\n"); 533 orw_rewind(); 534 ret = orw_expect("\\a", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 535 orw_expect("\\a", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 536 orw_close(); 537 return (ret); 538 } 539 540 T_FUNC(escaped_escapes_within_quotes, "escaped escapes within quotes") 541 { 542 int ret; 543 544 orw_open(); 545 orw_output("\"\\\\\" '\\\\'\n"); 546 orw_rewind(); 547 ret = orw_expect("\\", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 548 orw_expect("\\", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 549 orw_close(); 550 return (ret); 551 } 552 553 T_FUNC(escaped_quotes_within_quotes, "escaped quotes within quotes") 554 { 555 int ret; 556 557 orw_open(); 558 orw_output("\"\\\"\" '\\''\n"); 559 orw_rewind(); 560 ret = orw_expect("\"", 0 /*lines*/, 0 /*eof*/, 0 /*eol*/) && 561 orw_expect("'", 0 /*lines*/, 0 /*eof*/, 1 /*eol*/); 562 orw_close(); 563 return (ret); 564 } 565 566 567 568 /*************************************************************************** 569 * Boilerplate 570 */ 378 571 379 572 const struct t_test *t_plan[] = { … … 384 577 T(comment), 385 578 T(whitespace_before_comment), 579 386 580 T(single_word), 387 581 T(single_whitespace_before_word), … … 392 586 T(word_containing_hash), 393 587 T(two_words), 588 589 T(naked_escape), 590 T(escaped_escape), 591 T(escaped_whitespace), 592 T(escaped_letter), 593 594 T(naked_single_quote), 595 T(naked_double_quote), 394 596 T(empty_single_quotes), 395 597 T(empty_double_quotes), 598 T(quotes_within_quotes), 599 T(quoted_whitespace), 600 T(quoted_words), 601 602 T(escaped_quotes), 603 T(escaped_letters_within_quotes), 604 T(escaped_escapes_within_quotes), 605 T(escaped_quotes_within_quotes), 606 396 607 NULL 397 608 };
Note: See TracChangeset
for help on using the changeset viewer.