Changeset f4aa1c8 in mainline
- Timestamp:
- 2018-06-13T21:18:01Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 80f345c
- Parents:
- 39f84ce4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/test/stdio/scanf.c
r39f84ce4 rf4aa1c8 50 50 }; 51 51 52 /** Empty format string */ 52 53 PCUT_TEST(empty_fmt) 53 54 { 54 55 int rc; 55 56 56 /* Empty format string */57 57 rc = sscanf("42", ""); 58 58 PCUT_ASSERT_INT_EQUALS(0, rc); 59 59 } 60 60 61 /** Decimal integer */ 61 62 PCUT_TEST(dec_int) 62 63 { … … 64 65 int i; 65 66 66 /* Decimal integer */67 67 rc = sscanf("42", "%d", &i); 68 68 PCUT_ASSERT_INT_EQUALS(1, rc); … … 70 70 } 71 71 72 /** Two integers */ 72 73 PCUT_TEST(int_int) 73 74 { … … 75 76 int i, j; 76 77 77 /* Two integers */78 78 rc = sscanf("42 43", "%d%d", &i, &j); 79 79 PCUT_ASSERT_INT_EQUALS(2, rc); … … 82 82 } 83 83 84 /** Decimal signed char */ 84 85 PCUT_TEST(dec_sign_char) 85 86 { … … 87 88 signed char sc; 88 89 89 /* Decimal signed char */90 90 rc = sscanf("42", "%hhd", &sc); 91 91 PCUT_ASSERT_INT_EQUALS(1, rc); … … 93 93 } 94 94 95 /** Decimal short */ 95 96 PCUT_TEST(dec_short) 96 97 { … … 98 99 short si; 99 100 100 /* Decimal short */101 101 rc = sscanf("42", "%hd", &si); 102 102 PCUT_ASSERT_INT_EQUALS(1, rc); … … 104 104 } 105 105 106 /** Decimal long */ 106 107 PCUT_TEST(dec_long) 107 108 { … … 109 110 long li; 110 111 111 /* Decimal long */112 112 rc = sscanf("42", "%ld", &li); 113 113 PCUT_ASSERT_INT_EQUALS(1, rc); … … 115 115 } 116 116 117 /** Decimal long long */ 117 118 PCUT_TEST(dec_long_long) 118 119 { … … 120 121 long long lli; 121 122 122 /* Decimal long long */123 123 rc = sscanf("42", "%lld", &lli); 124 124 PCUT_ASSERT_INT_EQUALS(1, rc); … … 126 126 } 127 127 128 /** Decimal intmax_t */ 128 129 PCUT_TEST(dec_intmax) 129 130 { … … 131 132 intmax_t imax; 132 133 133 /* Decimal intmax_t */134 134 rc = sscanf("42", "%jd", &imax); 135 135 PCUT_ASSERT_INT_EQUALS(1, rc); … … 137 137 } 138 138 139 /** Decimal size_t-sized */ 139 140 PCUT_TEST(dec_size_t_size) 140 141 { … … 142 143 size_t szi; 143 144 144 /* Decimal size_t-sized */145 145 rc = sscanf("42", "%zd", &szi); 146 146 PCUT_ASSERT_INT_EQUALS(1, rc); … … 148 148 } 149 149 150 /** Decimal ptrdiff_t-sized */ 150 151 PCUT_TEST(dec_ptrdiff_t_size) 151 152 { … … 153 154 ptrdiff_t pdi; 154 155 155 /* Decimal ptrdiff_t-sized */156 156 rc = sscanf("42", "%td", &pdi); 157 157 PCUT_ASSERT_INT_EQUALS(1, rc); … … 159 159 } 160 160 161 /** Decimal integer followed by hexadecimal digit */ 161 162 PCUT_TEST(dec_int_hexdigit) 162 163 { … … 164 165 int i; 165 166 166 /* Decimal integer followed by hexadecimal digit */167 167 rc = sscanf("42a", "%d", &i); 168 168 PCUT_ASSERT_INT_EQUALS(1, rc); … … 170 170 } 171 171 172 /** Decimal integer - detect no prefix */ 172 173 PCUT_TEST(int_noprefix) 173 174 { … … 175 176 int i; 176 177 177 /* Decimal integer - detect no prefix */178 178 rc = sscanf("42", "%i", &i); 179 179 PCUT_ASSERT_INT_EQUALS(1, rc); … … 181 181 } 182 182 183 /** Prefixed octal integer followed by decimal digit */ 183 184 PCUT_TEST(octal_decimal_digit) 184 185 { … … 186 187 int i; 187 188 188 /* Prefixed octal integer followed by decimal digit */189 189 rc = sscanf("019", "%i", &i); 190 190 PCUT_ASSERT_INT_EQUALS(1, rc); … … 192 192 } 193 193 194 /** Prefixed hexadecimal integer followed by other character */ 194 195 PCUT_TEST(hex_other_char) 195 196 { … … 197 198 int i; 198 199 199 /* Prefixed hexadecimal integer followed by other character */200 200 rc = sscanf("0xag", "%i", &i); 201 201 PCUT_ASSERT_INT_EQUALS(1, rc); … … 203 203 } 204 204 205 /** Decimal integer with '+' sign */ 205 206 PCUT_TEST(positive_dec) 206 207 { … … 208 209 int i; 209 210 210 /* Decimal integer with '+' sign */211 211 rc = sscanf("+42", "%d", &i); 212 212 PCUT_ASSERT_INT_EQUALS(1, rc); … … 214 214 } 215 215 216 /** Decimal integer with '-' sign */ 216 217 PCUT_TEST(negative_dec) 217 218 { … … 219 220 int i; 220 221 221 /* Decimal integer with '-' sign */222 222 rc = sscanf("-42", "%d", &i); 223 223 PCUT_ASSERT_INT_EQUALS(1, rc); … … 225 225 } 226 226 227 /** Hexadecimal integer with prefix and '-' sign */ 227 228 PCUT_TEST(negative_hex) 228 229 { … … 230 231 int i; 231 232 232 /* Hexadecimal integer with prefix and '-' sign */233 233 rc = sscanf("-0xa", "%i", &i); 234 234 PCUT_ASSERT_INT_EQUALS(1, rc); … … 236 236 } 237 237 238 /** Decimal unsigned integer */ 238 239 PCUT_TEST(dec_unsigned) 239 240 { … … 241 242 unsigned u; 242 243 243 /* Decimal unsigned integer */244 244 rc = sscanf("42", "%u", &u); 245 245 PCUT_ASSERT_INT_EQUALS(1, rc); … … 247 247 } 248 248 249 /** Decimal unsigned char */ 249 250 PCUT_TEST(dec_unsigned_char) 250 251 { … … 252 253 unsigned char uc; 253 254 254 /* Decimal unsigned char */255 255 rc = sscanf("42", "%hhu", &uc); 256 256 PCUT_ASSERT_INT_EQUALS(1, rc); … … 258 258 } 259 259 260 /** Decimal unsigned short */ 260 261 PCUT_TEST(dec_unsigned_short) 261 262 { … … 263 264 unsigned short su; 264 265 265 /* Decimal unsigned short */266 266 rc = sscanf("42", "%hu", &su); 267 267 PCUT_ASSERT_INT_EQUALS(1, rc); … … 269 269 } 270 270 271 /** Decimal unsigned long */ 271 272 PCUT_TEST(dec_unsigned_long) 272 273 { … … 274 275 unsigned long lu; 275 276 276 /* Decimal unsigned long */277 277 rc = sscanf("42", "%lu", &lu); 278 278 PCUT_ASSERT_INT_EQUALS(1, rc); … … 280 280 } 281 281 282 /** Decimal unsigned long long */ 282 283 PCUT_TEST(dec_unsigned_long_long) 283 284 { … … 285 286 unsigned long long llu; 286 287 287 /* Decimal unsigned long long */288 288 rc = sscanf("42", "%llu", &llu); 289 289 PCUT_ASSERT_INT_EQUALS(1, rc); … … 291 291 } 292 292 293 /** Decimal uintmax_t */ 293 294 PCUT_TEST(dec_unitmax) 294 295 { … … 296 297 uintmax_t umax; 297 298 298 /* Decimal uintmax_t */299 299 rc = sscanf("42", "%ju", &umax); 300 300 PCUT_ASSERT_INT_EQUALS(1, rc); … … 302 302 } 303 303 304 /** Decimal size_t */ 304 305 PCUT_TEST(dec_unsigned_size) 305 306 { … … 307 308 size_t szu; 308 309 309 /* Decimal size_t */310 310 rc = sscanf("42", "%zu", &szu); 311 311 PCUT_ASSERT_INT_EQUALS(1, rc); … … 313 313 } 314 314 315 /** Decimal ptrdiff_t-sized unsigned int*/ 315 316 PCUT_TEST(dec_unsigned_ptrdiff) 316 317 { … … 318 319 ptrdiff_t pdu; 319 320 320 /* Decimal ptrdiff_t-sized unsigned int*/321 321 rc = sscanf("42", "%tu", &pdu); 322 322 PCUT_ASSERT_INT_EQUALS(1, rc); … … 324 324 } 325 325 326 /** Octal unsigned integer */ 326 327 PCUT_TEST(octal_unsigned) 327 328 { … … 329 330 unsigned u; 330 331 331 /* Octal unsigned integer */332 332 rc = sscanf("52", "%o", &u); 333 333 PCUT_ASSERT_INT_EQUALS(1, rc); … … 335 335 } 336 336 337 /** Hexadecimal unsigned integer */ 337 338 PCUT_TEST(hex_unsigned) 338 339 { … … 340 341 unsigned u; 341 342 342 /* Hexadecimal unsigned integer */343 343 rc = sscanf("2a", "%x", &u); 344 344 PCUT_ASSERT_INT_EQUALS(1, rc); … … 346 346 } 347 347 348 /** Hexadecimal unsigned integer unsing alternate specifier */ 348 349 PCUT_TEST(hex_unsigned_cap_x) 349 350 { … … 351 352 unsigned u; 352 353 353 /* Hexadecimal unsigned integer unsing alternate specifier */354 354 rc = sscanf("2a", "%X", &u); 355 355 PCUT_ASSERT_INT_EQUALS(1, rc); … … 357 357 } 358 358 359 /** Uppercase hexadecimal unsigned integer */ 359 360 PCUT_TEST(uppercase_hex_unsigned) 360 361 { … … 362 363 unsigned u; 363 364 364 /* Uppercase hexadecimal unsigned integer */365 365 rc = sscanf("2A", "%x", &u); 366 366 PCUT_ASSERT_INT_EQUALS(1, rc); … … 368 368 } 369 369 370 /** Make sure %x does not match 0x prefix */ 370 371 PCUT_TEST(hex_not_match_0x) 371 372 { … … 373 374 unsigned u; 374 375 375 /* Make sure %x does not match 0x prefix */376 376 rc = sscanf("0x1", "%x", &u); 377 377 … … 380 380 } 381 381 382 /** Skipping whitespace */ 382 383 PCUT_TEST(skipws) 383 384 { … … 385 386 int i; 386 387 387 /* Skipping whitespace */388 388 rc = sscanf(" \t\n42", "%d", &i); 389 389 PCUT_ASSERT_INT_EQUALS(1, rc); … … 391 391 } 392 392 393 /** Percentile conversion */ 393 394 PCUT_TEST(percentile) 394 395 { … … 396 397 int i; 397 398 398 /* Percentile conversion */399 399 rc = sscanf(" \t\n%42", "%%%d", &i); 400 400 PCUT_ASSERT_INT_EQUALS(1, rc); … … 402 402 } 403 403 404 /** Matching specific character */ 404 405 PCUT_TEST(match_spec_char) 405 406 { … … 407 408 int i; 408 409 409 /* Matching specific character */410 410 rc = sscanf("x42", "x%d", &i); 411 411 PCUT_ASSERT_INT_EQUALS(1, rc); … … 413 413 } 414 414 415 /** Matching specific character should not skip whitespace */ 415 416 PCUT_TEST(match_char_noskipws) 416 417 { … … 418 419 int i; 419 420 420 /* Matching specific character should not skip whitespace */421 421 rc = sscanf(" x42", "x%d", &i); 422 422 PCUT_ASSERT_INT_EQUALS(0, rc); 423 423 } 424 424 425 /** Skipping whitespace + match specific character */ 425 426 PCUT_TEST(skipws_match_char) 426 427 { … … 428 429 int i; 429 430 430 /* Skipping whitespace + match specific character */431 431 rc = sscanf(" x42", "\t\nx%d", &i); 432 432 PCUT_ASSERT_INT_EQUALS(1, rc); … … 434 434 } 435 435 436 /** Decimal with limited, but sufficient width */ 436 437 PCUT_TEST(dec_sufficient_lim_width) 437 438 { … … 439 440 int i; 440 441 441 /* Decimal with limited, but sufficient width */442 442 rc = sscanf("42", "%2d", &i); 443 443 PCUT_ASSERT_INT_EQUALS(1, rc); … … 445 445 } 446 446 447 /** Decimal with limited, smaller width */ 447 448 PCUT_TEST(dec_smaller_width) 448 449 { … … 450 451 int i; 451 452 452 /* Decimal with limited, smaller width */453 453 rc = sscanf("42", "%1d", &i); 454 454 PCUT_ASSERT_INT_EQUALS(1, rc); … … 456 456 } 457 457 458 /** Integer with hex prefix, format with limited, sufficient width */ 458 459 PCUT_TEST(int_hex_limited_width) 459 460 { … … 461 462 int i; 462 463 463 /* Integer with hex prefix, format with limited, sufficient width */464 464 rc = sscanf("0x1", "%3i", &i); 465 465 PCUT_ASSERT_INT_EQUALS(1, rc); … … 467 467 } 468 468 469 /** Integer with hex prefix, format with limited, smaller width */ 469 470 PCUT_TEST(int_hex_small_width) 470 471 { … … 472 473 int i; 473 474 474 /* Integer with hex prefix, format with limited, smaller width */475 475 rc = sscanf("0x1", "%2i", &i); 476 476 PCUT_ASSERT_INT_EQUALS(1, rc); … … 478 478 } 479 479 480 /** Integer with octal prefix, format with limited, sufficient width */ 480 481 PCUT_TEST(int_oct_limited_width) 481 482 { … … 483 484 int i; 484 485 485 /* Integer with octal prefix, format with limited, sufficient width */486 486 rc = sscanf("012", "%3i", &i); 487 487 PCUT_ASSERT_INT_EQUALS(1, rc); … … 489 489 } 490 490 491 /** Integer with octal prefix, format with limited, smaller width */ 491 492 PCUT_TEST(int_oct_smaller_width) 492 493 { … … 494 495 int i; 495 496 496 /* Integer with octal prefix, format with limited, smaller width */497 497 rc = sscanf("012", "%2i", &i); 498 498 PCUT_ASSERT_INT_EQUALS(1, rc); … … 500 500 } 501 501 502 /** Integer with octal prefix, format with width allowing just for 0 */ 502 503 PCUT_TEST(int_oct_tiny_width) 503 504 { … … 505 506 int i; 506 507 507 /* Integer with octal prefix, format with width allowing just for 0 */508 508 rc = sscanf("012", "%1i", &i); 509 509 PCUT_ASSERT_INT_EQUALS(1, rc); … … 511 511 } 512 512 513 /** Pointer */ 513 514 PCUT_TEST(pointer) 514 515 { … … 516 517 void *ptr; 517 518 518 /* Pointer */519 519 rc = sscanf("0xABCDEF88", "%p", &ptr); 520 520 PCUT_ASSERT_INT_EQUALS(1, rc); … … 522 522 } 523 523 524 /** Single character */ 524 525 PCUT_TEST(single_char) 525 526 { … … 527 528 char c; 528 529 529 /* Single character */530 530 rc = sscanf("x", "%c", &c); 531 531 PCUT_ASSERT_INT_EQUALS(1, rc); … … 533 533 } 534 534 535 /** Single whitespace character */ 535 536 PCUT_TEST(single_ws_char) 536 537 { … … 538 539 char c; 539 540 540 /* Single whitespace character */541 541 rc = sscanf("\t", "%c", &c); 542 542 PCUT_ASSERT_INT_EQUALS(1, rc); … … 544 544 } 545 545 546 /** Multiple characters */ 546 547 PCUT_TEST(chars) 547 548 { … … 549 550 char chars[chars_size]; 550 551 551 /* Multiple characters */552 552 memset(chars, 'X', chars_size); 553 553 rc = sscanf("abc", "%3c", chars); … … 559 559 } 560 560 561 /** Fewer characters than requested */ 561 562 PCUT_TEST(fewer_chars) 562 563 { … … 564 565 char chars[chars_size]; 565 566 566 /* Fewer characters than requested */567 567 memset(chars, 'X', chars_size); 568 568 rc = sscanf("abc", "%5c", chars); … … 574 574 } 575 575 576 /** Reading characters but no found */ 576 577 PCUT_TEST(chars_not_found) 577 578 { … … 579 580 char chars[chars_size]; 580 581 581 /* Reading characters but no found */582 582 memset(chars, 'X', chars_size); 583 583 rc = sscanf("", "%5c", chars); … … 586 586 } 587 587 588 /** Multiple characters with suppressed assignment */ 588 589 PCUT_TEST(chars_noassign) 589 590 { … … 591 592 int n; 592 593 593 /* Multiple characters with suppressed assignment */594 594 rc = sscanf("abc", "%*3c%n", &n); 595 595 PCUT_ASSERT_INT_EQUALS(0, rc); … … 597 597 } 598 598 599 /** Multiple characters with memory allocation */ 599 600 PCUT_TEST(chars_malloc) 600 601 { … … 602 603 char *cp; 603 604 604 /* Multiple characters with memory allocation */605 605 cp = NULL; 606 606 rc = sscanf("abc", "%m3c", &cp); … … 613 613 } 614 614 615 /** String of non-whitespace characters, unlimited width */ 615 616 PCUT_TEST(str) 616 617 { … … 618 619 char chars[chars_size]; 619 620 620 /* String of non-whitespace characters, unlimited width */621 621 memset(chars, 'X', chars_size); 622 622 rc = sscanf(" abc d", "%s", chars); … … 629 629 } 630 630 631 /** String of non-whitespace characters, until the end */ 631 632 PCUT_TEST(str_till_end) 632 633 { … … 634 635 char chars[chars_size]; 635 636 636 /* String of non-whitespace characters, until the end */637 637 memset(chars, 'X', chars_size); 638 638 rc = sscanf(" abc", "%s", chars); … … 645 645 } 646 646 647 /** String of non-whitespace characters, large enough width */ 647 648 PCUT_TEST(str_large_width) 648 649 { … … 650 651 char chars[chars_size]; 651 652 652 /* String of non-whitespace characters, large enough width */653 653 memset(chars, 'X', chars_size); 654 654 rc = sscanf(" abc d", "%5s", chars); … … 661 661 } 662 662 663 /** Want string of non-whitespace, but got only whitespace */ 663 664 PCUT_TEST(str_not_found) 664 665 { … … 666 667 char chars[chars_size]; 667 668 668 /* Want string of non-whitespace, but got only whitespace */669 669 memset(chars, 'X', chars_size); 670 670 rc = sscanf(" ", "%s", chars); … … 673 673 } 674 674 675 /** String of non-whitespace characters, small width */ 675 676 PCUT_TEST(str_small_width) 676 677 { … … 678 679 char chars[chars_size]; 679 680 680 /* String of non-whitespace characters, small width */681 681 memset(chars, 'X', chars_size); 682 682 rc = sscanf(" abc", "%2s", chars); … … 688 688 } 689 689 690 /** String of non-whitespace characters, assignment suppression */ 690 691 PCUT_TEST(str_noassign) 691 692 { … … 693 694 int n; 694 695 695 /* String of non-whitespace characters, assignment suppression */696 696 rc = sscanf(" abc d", "%*s%n", &n); 697 697 PCUT_ASSERT_INT_EQUALS(0, rc); … … 699 699 } 700 700 701 /** String of non-whitespace characters, memory allocation */ 701 702 PCUT_TEST(str_malloc) 702 703 { … … 704 705 char *cp; 705 706 706 /* String of non-whitespace characters, memory allocation */707 707 rc = sscanf(" abc d", "%ms", &cp); 708 708 PCUT_ASSERT_INT_EQUALS(1, rc); … … 715 715 } 716 716 717 /** Set conversion without width specified terminating before the end */ 717 718 PCUT_TEST(set_convert) 718 719 { … … 721 722 int i; 722 723 723 /* Set conversion without width specified terminating before the end */724 724 memset(chars, 'X', chars_size); 725 725 rc = sscanf("abcd42", "%[abc]d%d", chars, &i); … … 733 733 } 734 734 735 /** Set conversion without width specified, until the end */ 735 736 PCUT_TEST(set_till_end) 736 737 { … … 738 739 char chars[chars_size]; 739 740 740 /* Set conversion without width specified, until the end */741 741 memset(chars, 'X', chars_size); 742 742 rc = sscanf("abc", "%[abc]", chars); … … 749 749 } 750 750 751 /** Set conversion with larger width */ 751 752 PCUT_TEST(set_large_width) 752 753 { … … 754 755 char chars[chars_size]; 755 756 756 /* Set conversion with larger width */757 757 memset(chars, 'X', chars_size); 758 758 rc = sscanf("abcd", "%5[abc]", chars); … … 765 765 } 766 766 767 /** Set conversion with smaller width */ 767 768 PCUT_TEST(set_small_width) 768 769 { … … 770 771 char chars[chars_size]; 771 772 772 /* Set conversion with smaller width */773 773 memset(chars, 'X', chars_size); 774 774 rc = sscanf("abcd", "%3[abcd]", chars); … … 781 781 } 782 782 783 /** Set conversion with negated scanset */ 783 784 PCUT_TEST(set_inverted) 784 785 { … … 786 787 char chars[chars_size]; 787 788 788 /* Set conversion with negated scanset */789 789 memset(chars, 'X', chars_size); 790 790 rc = sscanf("abcd", "%[^d]", chars); … … 797 797 } 798 798 799 /** Set conversion with ']' in scanset */ 799 800 PCUT_TEST(set_with_rbr) 800 801 { … … 802 803 char chars[chars_size]; 803 804 804 /* Set conversion with ']' in scanset */805 805 memset(chars, 'X', chars_size); 806 806 rc = sscanf("]bcd", "%[]bc]", chars); … … 813 813 } 814 814 815 /** Set conversion with ']' in inverted scanset */ 815 816 PCUT_TEST(set_inverted_with_rbr) 816 817 { … … 818 819 char chars[chars_size]; 819 820 820 /* Set conversion with ']' in inverted scanset */821 821 memset(chars, 'X', chars_size); 822 822 rc = sscanf("abc]", "%[^]def]", chars); … … 829 829 } 830 830 831 /** Set conversion with leading '-' in scanset */ 831 832 PCUT_TEST(set_with_leading_dash) 832 833 { … … 834 835 char chars[chars_size]; 835 836 836 /* Set conversion with leading '-' in scanset */837 837 memset(chars, 'X', chars_size); 838 838 rc = sscanf("a-bc[", "%[-abc]", chars); … … 846 846 } 847 847 848 /** Set conversion with trailing '-' in scanset */ 848 849 PCUT_TEST(set_with_trailing_dash) 849 850 { … … 851 852 char chars[chars_size]; 852 853 853 /* Set conversion with trailing '-' in scanset */854 854 memset(chars, 'X', chars_size); 855 855 rc = sscanf("a-bc]", "%[abc-]", chars); … … 863 863 } 864 864 865 /** Set conversion with leading '-' in inverted scanset */ 865 866 PCUT_TEST(set_inverted_with_leading_dash) 866 867 { … … 868 869 char chars[chars_size]; 869 870 870 /* Set conversion with leading '-' in inverted scanset */871 871 memset(chars, 'X', chars_size); 872 872 rc = sscanf("def-", "%[^-abc]", chars); … … 879 879 } 880 880 881 /** ']' after '^' in scanset does not lose meaning of scanset delimiter */ 881 882 PCUT_TEST(set_inverted_with_only_dash) 882 883 { … … 884 885 char chars[chars_size]; 885 886 886 /*887 * ']' after '^' in scanset does not lose meaning of scanset888 * delimiter889 */890 887 memset(chars, 'X', chars_size); 891 888 rc = sscanf("abc-", "%[^-]", chars); … … 898 895 } 899 896 897 /** '^' after '-' in scanset does not have special meaning */ 900 898 PCUT_TEST(set_inverted_with_dash_caret) 901 899 { … … 903 901 char chars[chars_size]; 904 902 905 /* '^' after '-' in scanset does not have special meaning */906 903 memset(chars, 'X', chars_size); 907 904 rc = sscanf("-^a", "%[-^a]", chars); … … 914 911 } 915 912 913 /** Set conversion with range (GNU extension) */ 914 PCUT_TEST(set_with_range) 915 { 916 int rc; 917 char chars[chars_size]; 918 919 memset(chars, 'X', chars_size); 920 rc = sscanf("abc]", "%[a-c]", chars); 921 PCUT_ASSERT_INT_EQUALS(1, rc); 922 PCUT_ASSERT_TRUE(chars[0] == 'a'); 923 PCUT_ASSERT_TRUE(chars[1] == 'b'); 924 PCUT_ASSERT_TRUE(chars[2] == 'c'); 925 PCUT_ASSERT_TRUE(chars[3] == '\0'); 926 PCUT_ASSERT_TRUE(chars[4] == 'X'); 927 } 928 929 /** Set conversion with range (GNU extension) in inverted scanset */ 930 PCUT_TEST(set_inverted_with_range) 931 { 932 int rc; 933 char chars[chars_size]; 934 935 memset(chars, 'X', chars_size); 936 rc = sscanf("defb", "%[^a-c]", chars); 937 PCUT_ASSERT_INT_EQUALS(1, rc); 938 PCUT_ASSERT_TRUE(chars[0] == 'd'); 939 PCUT_ASSERT_TRUE(chars[1] == 'e'); 940 PCUT_ASSERT_TRUE(chars[2] == 'f'); 941 PCUT_ASSERT_TRUE(chars[3] == '\0'); 942 PCUT_ASSERT_TRUE(chars[4] == 'X'); 943 } 944 945 /** Set conversion with assignment suppression */ 916 946 PCUT_TEST(set_noassign) 917 947 { … … 919 949 int n; 920 950 921 /* Set conversion with assignment suppression */922 951 rc = sscanf("abcd42", "%*[abc]%n", &n); 923 952 PCUT_ASSERT_INT_EQUALS(0, rc); … … 925 954 } 926 955 956 /** Set conversion with memory allocation */ 927 957 PCUT_TEST(set_malloc) 928 958 { … … 930 960 char *cp; 931 961 932 /* Set conversion with memory allocation */933 962 cp = NULL; 934 963 rc = sscanf("abcd42", "%m[abcd]", &cp); … … 943 972 } 944 973 974 /** Decimal integer with suppressed assignment */ 945 975 PCUT_TEST(dec_int_noassign) 946 976 { … … 948 978 int n; 949 979 950 /* Decimal integer with suppressed assignment */951 980 rc = sscanf("42", "%*d%n", &n); 952 981 PCUT_ASSERT_INT_EQUALS(0, rc); … … 954 983 } 955 984 985 /** Count of characters read */ 956 986 PCUT_TEST(count_chars) 957 987 { … … 960 990 int n; 961 991 962 /* Count of characters read */963 992 memset(chars, 'X', chars_size); 964 993 rc = sscanf("abcd", "%3c%n", chars, &n); … … 971 1000 } 972 1001 1002 /** Float with just integer part */ 973 1003 PCUT_TEST(float_intpart_only) 974 1004 { … … 976 1006 float f; 977 1007 978 /* Float with just integer part */979 1008 rc = sscanf("42", "%f", &f); 980 1009 PCUT_ASSERT_INT_EQUALS(1, rc); … … 982 1011 } 983 1012 1013 /** Double with just integer part */ 984 1014 PCUT_TEST(double_intpart_only) 985 1015 { … … 987 1017 double d; 988 1018 989 /* Double with just integer part */990 1019 rc = sscanf("42", "%lf", &d); 991 1020 PCUT_ASSERT_INT_EQUALS(1, rc); … … 993 1022 } 994 1023 1024 /** Long double with just integer part */ 995 1025 PCUT_TEST(ldouble_intpart_only) 996 1026 { … … 998 1028 long double ld; 999 1029 1000 /* Long double with just integer part */1001 1030 rc = sscanf("42", "%Lf", &ld); 1002 1031 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1004 1033 } 1005 1034 1035 /** Float with just hexadecimal integer part */ 1006 1036 PCUT_TEST(float_hex_intpart_only) 1007 1037 { … … 1009 1039 float f; 1010 1040 1011 /* Float with just hexadecimal integer part */1012 1041 rc = sscanf("0x2a", "%f", &f); 1013 1042 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1015 1044 } 1016 1045 1046 /** Float with sign and integer part */ 1017 1047 PCUT_TEST(float_sign_intpart) 1018 1048 { … … 1020 1050 float f; 1021 1051 1022 /* Float with sign and integer part */1023 1052 rc = sscanf("-42", "%f", &f); 1024 1053 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1026 1055 } 1027 1056 1057 /** Float with integer and fractional part */ 1028 1058 PCUT_TEST(float_intpart_fract) 1029 1059 { … … 1031 1061 float f; 1032 1062 1033 /* Float with integer and fractional part */1034 1063 rc = sscanf("4.2", "%f", &f); 1035 1064 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1039 1068 } 1040 1069 1070 /** Float with integer part and unsigned exponent */ 1041 1071 PCUT_TEST(float_intpart_exp) 1042 1072 { … … 1044 1074 float f; 1045 1075 1046 /* Float with integer part and unsigned exponent */1047 1076 rc = sscanf("42e1", "%f", &f); 1048 1077 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1050 1079 } 1051 1080 1081 1082 /** Float with integer part and positive exponent */ 1052 1083 PCUT_TEST(float_intpart_posexp) 1053 1084 { 1054 1085 int rc; 1055 1086 float f; 1056 1057 /* Float with integer part and positive exponent */1058 1087 rc = sscanf("42e+1", "%f", &f); 1059 1088 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1061 1090 } 1062 1091 1092 /** Float with integer part and negative exponent */ 1063 1093 PCUT_TEST(float_intpart_negexp) 1064 1094 { … … 1066 1096 float f; 1067 1097 1068 /* Float with integer part and negative exponent */1069 1098 rc = sscanf("42e-1", "%f", &f); 1070 1099 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1074 1103 } 1075 1104 1105 /** Float with integer, fractional parts and unsigned exponent */ 1076 1106 PCUT_TEST(float_intpart_fract_exp) 1077 1107 { … … 1079 1109 float f; 1080 1110 1081 /* Float with integer, fractional parts and unsigned exponent */1082 1111 rc = sscanf("4.2e1", "%f", &f); 1083 1112 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1085 1114 } 1086 1115 1116 /** Hexadecimal float with integer and fractional part */ 1087 1117 PCUT_TEST(hexfloat_intpart_fract) 1088 1118 { … … 1090 1120 float f; 1091 1121 1092 /* Hexadecimal float with integer and fractional part */1093 1122 rc = sscanf("0x2.a", "%f", &f); 1094 1123 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1096 1125 } 1097 1126 1127 /** Hexadecimal float with integer part and unsigned exponent */ 1098 1128 PCUT_TEST(hexfloat_intpart_exp) 1099 1129 { … … 1101 1131 float f; 1102 1132 1103 /*1104 * Hexadecimal float with integer part and unsigned exponent1105 */1106 1133 rc = sscanf("0x2ap1", "%f", &f); 1107 1134 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1109 1136 } 1110 1137 1138 /** Hexadecimal float with integer part and negative exponent */ 1111 1139 PCUT_TEST(hexfloat_intpart_negexp) 1112 1140 { … … 1114 1142 float f; 1115 1143 1116 /*1117 * Hexadecimal float with integer part and negative exponent1118 */1119 1144 rc = sscanf("0x2ap-1", "%f", &f); 1120 1145 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1122 1147 } 1123 1148 1149 /** Hexadecimal float with integer, fractional parts and unsigned exponent */ 1124 1150 PCUT_TEST(hexfloat_intpart_fract_exp) 1125 1151 { … … 1127 1153 float f; 1128 1154 1129 /*1130 * Hexadecimal float with integer, fractional parts and unsigned1131 * exponent1132 */1133 1155 rc = sscanf("0x2.ap4", "%f", &f); 1134 1156 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1136 1158 } 1137 1159 1160 /** Float with just integer part and limited width */ 1138 1161 PCUT_TEST(float_intpart_limwidth) 1139 1162 { … … 1141 1164 float f; 1142 1165 1143 /* Float with just integer part and limited width */1144 1166 rc = sscanf("1234", "%3f", &f); 1145 1167 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1147 1169 } 1148 1170 1171 /** Float with integer, fractional part and limited width */ 1149 1172 PCUT_TEST(float_intpart_fract_limwidth) 1150 1173 { … … 1152 1175 float f; 1153 1176 1154 /* Float with integer, fractional part and limited width */1155 1177 rc = sscanf("12.34", "%4f", &f); 1156 1178 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1160 1182 } 1161 1183 1184 /** Float with width only enough to cover an integral part */ 1162 1185 PCUT_TEST(float_width_for_only_intpart) 1163 1186 { … … 1165 1188 float f; 1166 1189 1167 /* Float with width only enough to cover an integral part */1168 1190 rc = sscanf("12.34", "%3f", &f); 1169 1191 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1171 1193 } 1172 1194 1195 /** Float with width too small to cover the exponent number */ 1173 1196 PCUT_TEST(float_width_small_for_expnum) 1174 1197 { … … 1176 1199 float f; 1177 1200 1178 /* Float with width too small to cover the exponent number */1179 1201 rc = sscanf("12.34e+2", "%7f", &f); 1180 1202 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1184 1206 } 1185 1207 1208 /** Float with width too small to cover the exponent sign and number */ 1186 1209 PCUT_TEST(float_width_small_for_expsignum) 1187 1210 { … … 1189 1212 float f; 1190 1213 1191 /* Float with width too small to cover the exponent sign and number */1192 1214 rc = sscanf("12.34e+2", "%6f", &f); 1193 1215 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1197 1219 } 1198 1220 1221 /** Float with width too small to cover the exponent part */ 1199 1222 PCUT_TEST(float_width_small_for_exp) 1200 1223 { … … 1202 1225 float f; 1203 1226 1204 /* Float with width too small to cover the exponent part */1205 1227 rc = sscanf("12.34e+2", "%5f", &f); 1206 1228 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1210 1232 } 1211 1233 1234 /** Float using alternate form 'F' */ 1212 1235 PCUT_TEST(float_cap_f) 1213 1236 { … … 1215 1238 float f; 1216 1239 1217 /* Float using alternate form 'F' */1218 1240 rc = sscanf("42e1", "%F", &f); 1219 1241 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1221 1243 } 1222 1244 1245 /** Float using alternate form 'a' */ 1223 1246 PCUT_TEST(float_a) 1224 1247 { … … 1226 1249 float f; 1227 1250 1228 /* Float using alternate form 'a' */1229 1251 rc = sscanf("42e1", "%a", &f); 1230 1252 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1232 1254 } 1233 1255 1256 /** Float using alternate form 'e' */ 1234 1257 PCUT_TEST(float_e) 1235 1258 { … … 1237 1260 float f; 1238 1261 1239 /* Float using alternate form 'e' */1240 1262 rc = sscanf("42e1", "%e", &f); 1241 1263 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1243 1265 } 1244 1266 1267 /** Float using alternate form 'g' */ 1245 1268 PCUT_TEST(float_g) 1246 1269 { … … 1248 1271 float f; 1249 1272 1250 /* Float using alternate form 'g' */1251 1273 rc = sscanf("42e1", "%g", &f); 1252 1274 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1254 1276 } 1255 1277 1278 /** Float using alternate form 'A' */ 1256 1279 PCUT_TEST(float_cap_a) 1257 1280 { … … 1259 1282 float f; 1260 1283 1261 /* Float using alternate form 'A' */1262 1284 rc = sscanf("42e1", "%A", &f); 1263 1285 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1265 1287 } 1266 1288 1289 /** Float using alternate form 'E' */ 1267 1290 PCUT_TEST(float_cap_e) 1268 1291 { … … 1270 1293 float f; 1271 1294 1272 /* Float using alternate form 'E' */1273 1295 rc = sscanf("42e1", "%E", &f); 1274 1296 PCUT_ASSERT_INT_EQUALS(1, rc); … … 1276 1298 } 1277 1299 1300 /** Float using alternate form 'G' */ 1278 1301 PCUT_TEST(float_cap_g) 1279 1302 { … … 1281 1304 float f; 1282 1305 1283 /* Float using alternate form 'G' */1284 1306 rc = sscanf("42e1", "%G", &f); 1285 1307 PCUT_ASSERT_INT_EQUALS(1, rc);
Note:
See TracChangeset
for help on using the changeset viewer.