Changeset f4aa1c8 in mainline


Ignore:
Timestamp:
2018-06-13T21:18:01Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
80f345c
Parents:
39f84ce4
Message:

Add actual test for using range in scanf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/test/stdio/scanf.c

    r39f84ce4 rf4aa1c8  
    5050};
    5151
     52/** Empty format string */
    5253PCUT_TEST(empty_fmt)
    5354{
    5455        int rc;
    5556
    56         /* Empty format string */
    5757        rc = sscanf("42", "");
    5858        PCUT_ASSERT_INT_EQUALS(0, rc);
    5959}
    6060
     61/** Decimal integer */
    6162PCUT_TEST(dec_int)
    6263{
     
    6465        int i;
    6566
    66         /* Decimal integer */
    6767        rc = sscanf("42", "%d", &i);
    6868        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    7070}
    7171
     72/** Two integers */
    7273PCUT_TEST(int_int)
    7374{
     
    7576        int i, j;
    7677
    77         /* Two integers */
    7878        rc = sscanf("42 43", "%d%d", &i, &j);
    7979        PCUT_ASSERT_INT_EQUALS(2, rc);
     
    8282}
    8383
     84/** Decimal signed char */
    8485PCUT_TEST(dec_sign_char)
    8586{
     
    8788        signed char sc;
    8889
    89         /* Decimal signed char */
    9090        rc = sscanf("42", "%hhd", &sc);
    9191        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    9393}
    9494
     95/** Decimal short */
    9596PCUT_TEST(dec_short)
    9697{
     
    9899        short si;
    99100
    100         /* Decimal short */
    101101        rc = sscanf("42", "%hd", &si);
    102102        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    104104}
    105105
     106/** Decimal long */
    106107PCUT_TEST(dec_long)
    107108{
     
    109110        long li;
    110111
    111         /* Decimal long */
    112112        rc = sscanf("42", "%ld", &li);
    113113        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    115115}
    116116
     117/** Decimal long long */
    117118PCUT_TEST(dec_long_long)
    118119{
     
    120121        long long lli;
    121122
    122         /* Decimal long long */
    123123        rc = sscanf("42", "%lld", &lli);
    124124        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    126126}
    127127
     128/** Decimal intmax_t */
    128129PCUT_TEST(dec_intmax)
    129130{
     
    131132        intmax_t imax;
    132133
    133         /* Decimal intmax_t */
    134134        rc = sscanf("42", "%jd", &imax);
    135135        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    137137}
    138138
     139/** Decimal size_t-sized */
    139140PCUT_TEST(dec_size_t_size)
    140141{
     
    142143        size_t szi;
    143144
    144         /* Decimal size_t-sized */
    145145        rc = sscanf("42", "%zd", &szi);
    146146        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    148148}
    149149
     150/** Decimal ptrdiff_t-sized */
    150151PCUT_TEST(dec_ptrdiff_t_size)
    151152{
     
    153154        ptrdiff_t pdi;
    154155
    155         /* Decimal ptrdiff_t-sized */
    156156        rc = sscanf("42", "%td", &pdi);
    157157        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    159159}
    160160
     161/** Decimal integer followed by hexadecimal digit */
    161162PCUT_TEST(dec_int_hexdigit)
    162163{
     
    164165        int i;
    165166
    166         /* Decimal integer followed by hexadecimal digit */
    167167        rc = sscanf("42a", "%d", &i);
    168168        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    170170}
    171171
     172/** Decimal integer - detect no prefix */
    172173PCUT_TEST(int_noprefix)
    173174{
     
    175176        int i;
    176177
    177         /* Decimal integer - detect no prefix */
    178178        rc = sscanf("42", "%i", &i);
    179179        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    181181}
    182182
     183/** Prefixed octal integer followed by decimal digit */
    183184PCUT_TEST(octal_decimal_digit)
    184185{
     
    186187        int i;
    187188
    188         /* Prefixed octal integer followed by decimal digit */
    189189        rc = sscanf("019", "%i", &i);
    190190        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    192192}
    193193
     194/** Prefixed hexadecimal integer followed by other character */
    194195PCUT_TEST(hex_other_char)
    195196{
     
    197198        int i;
    198199
    199         /* Prefixed hexadecimal integer followed by other character */
    200200        rc = sscanf("0xag", "%i", &i);
    201201        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    203203}
    204204
     205/** Decimal integer with '+' sign */
    205206PCUT_TEST(positive_dec)
    206207{
     
    208209        int i;
    209210
    210         /* Decimal integer with '+' sign */
    211211        rc = sscanf("+42", "%d", &i);
    212212        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    214214}
    215215
     216/** Decimal integer with '-' sign */
    216217PCUT_TEST(negative_dec)
    217218{
     
    219220        int i;
    220221
    221         /* Decimal integer with '-' sign */
    222222        rc = sscanf("-42", "%d", &i);
    223223        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    225225}
    226226
     227/** Hexadecimal integer with prefix and '-' sign */
    227228PCUT_TEST(negative_hex)
    228229{
     
    230231        int i;
    231232
    232         /* Hexadecimal integer with prefix and '-' sign */
    233233        rc = sscanf("-0xa", "%i", &i);
    234234        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    236236}
    237237
     238/** Decimal unsigned integer */
    238239PCUT_TEST(dec_unsigned)
    239240{
     
    241242        unsigned u;
    242243
    243         /* Decimal unsigned integer */
    244244        rc = sscanf("42", "%u", &u);
    245245        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    247247}
    248248
     249/** Decimal unsigned char */
    249250PCUT_TEST(dec_unsigned_char)
    250251{
     
    252253        unsigned char uc;
    253254
    254         /* Decimal unsigned char */
    255255        rc = sscanf("42", "%hhu", &uc);
    256256        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    258258}
    259259
     260/** Decimal unsigned short */
    260261PCUT_TEST(dec_unsigned_short)
    261262{
     
    263264        unsigned short su;
    264265
    265         /* Decimal unsigned short */
    266266        rc = sscanf("42", "%hu", &su);
    267267        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    269269}
    270270
     271/** Decimal unsigned long */
    271272PCUT_TEST(dec_unsigned_long)
    272273{
     
    274275        unsigned long lu;
    275276
    276         /* Decimal unsigned long */
    277277        rc = sscanf("42", "%lu", &lu);
    278278        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    280280}
    281281
     282/** Decimal unsigned long long */
    282283PCUT_TEST(dec_unsigned_long_long)
    283284{
     
    285286        unsigned long long llu;
    286287
    287         /* Decimal unsigned long long */
    288288        rc = sscanf("42", "%llu", &llu);
    289289        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    291291}
    292292
     293/** Decimal uintmax_t */
    293294PCUT_TEST(dec_unitmax)
    294295{
     
    296297        uintmax_t umax;
    297298
    298         /* Decimal uintmax_t */
    299299        rc = sscanf("42", "%ju", &umax);
    300300        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    302302}
    303303
     304/** Decimal size_t */
    304305PCUT_TEST(dec_unsigned_size)
    305306{
     
    307308        size_t szu;
    308309
    309         /* Decimal size_t */
    310310        rc = sscanf("42", "%zu", &szu);
    311311        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    313313}
    314314
     315/** Decimal ptrdiff_t-sized unsigned int*/
    315316PCUT_TEST(dec_unsigned_ptrdiff)
    316317{
     
    318319        ptrdiff_t pdu;
    319320
    320         /* Decimal ptrdiff_t-sized unsigned int*/
    321321        rc = sscanf("42", "%tu", &pdu);
    322322        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    324324}
    325325
     326/** Octal unsigned integer */
    326327PCUT_TEST(octal_unsigned)
    327328{
     
    329330        unsigned u;
    330331
    331         /* Octal unsigned integer */
    332332        rc = sscanf("52", "%o", &u);
    333333        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    335335}
    336336
     337/** Hexadecimal unsigned integer */
    337338PCUT_TEST(hex_unsigned)
    338339{
     
    340341        unsigned u;
    341342
    342         /* Hexadecimal unsigned integer */
    343343        rc = sscanf("2a", "%x", &u);
    344344        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    346346}
    347347
     348/** Hexadecimal unsigned integer unsing alternate specifier */
    348349PCUT_TEST(hex_unsigned_cap_x)
    349350{
     
    351352        unsigned u;
    352353
    353         /* Hexadecimal unsigned integer unsing alternate specifier */
    354354        rc = sscanf("2a", "%X", &u);
    355355        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    357357}
    358358
     359/** Uppercase hexadecimal unsigned integer */
    359360PCUT_TEST(uppercase_hex_unsigned)
    360361{
     
    362363        unsigned u;
    363364
    364         /* Uppercase hexadecimal unsigned integer */
    365365        rc = sscanf("2A", "%x", &u);
    366366        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    368368}
    369369
     370/** Make sure %x does not match 0x prefix */
    370371PCUT_TEST(hex_not_match_0x)
    371372{
     
    373374        unsigned u;
    374375
    375         /* Make sure %x does not match 0x prefix */
    376376        rc = sscanf("0x1", "%x", &u);
    377377
     
    380380}
    381381
     382/** Skipping whitespace */
    382383PCUT_TEST(skipws)
    383384{
     
    385386        int i;
    386387
    387         /* Skipping whitespace */
    388388        rc = sscanf(" \t\n42", "%d", &i);
    389389        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    391391}
    392392
     393/** Percentile conversion */
    393394PCUT_TEST(percentile)
    394395{
     
    396397        int i;
    397398
    398         /* Percentile conversion */
    399399        rc = sscanf(" \t\n%42", "%%%d", &i);
    400400        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    402402}
    403403
     404/** Matching specific character */
    404405PCUT_TEST(match_spec_char)
    405406{
     
    407408        int i;
    408409
    409         /* Matching specific character */
    410410        rc = sscanf("x42", "x%d", &i);
    411411        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    413413}
    414414
     415/** Matching specific character should not skip whitespace */
    415416PCUT_TEST(match_char_noskipws)
    416417{
     
    418419        int i;
    419420
    420         /* Matching specific character should not skip whitespace */
    421421        rc = sscanf(" x42", "x%d", &i);
    422422        PCUT_ASSERT_INT_EQUALS(0, rc);
    423423}
    424424
     425/** Skipping whitespace + match specific character */
    425426PCUT_TEST(skipws_match_char)
    426427{
     
    428429        int i;
    429430
    430         /* Skipping whitespace + match specific character */
    431431        rc = sscanf(" x42", "\t\nx%d", &i);
    432432        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    434434}
    435435
     436/** Decimal with limited, but sufficient width */
    436437PCUT_TEST(dec_sufficient_lim_width)
    437438{
     
    439440        int i;
    440441
    441         /* Decimal with limited, but sufficient width */
    442442        rc = sscanf("42", "%2d", &i);
    443443        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    445445}
    446446
     447/** Decimal with limited, smaller width */
    447448PCUT_TEST(dec_smaller_width)
    448449{
     
    450451        int i;
    451452
    452         /* Decimal with limited, smaller width */
    453453        rc = sscanf("42", "%1d", &i);
    454454        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    456456}
    457457
     458/** Integer with hex prefix, format with limited, sufficient width */
    458459PCUT_TEST(int_hex_limited_width)
    459460{
     
    461462        int i;
    462463
    463         /* Integer with hex prefix, format with limited, sufficient width */
    464464        rc = sscanf("0x1", "%3i", &i);
    465465        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    467467}
    468468
     469/** Integer with hex prefix, format with limited, smaller width */
    469470PCUT_TEST(int_hex_small_width)
    470471{
     
    472473        int i;
    473474
    474         /* Integer with hex prefix, format with limited, smaller width */
    475475        rc = sscanf("0x1", "%2i", &i);
    476476        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    478478}
    479479
     480/** Integer with octal prefix, format with limited, sufficient width */
    480481PCUT_TEST(int_oct_limited_width)
    481482{
     
    483484        int i;
    484485
    485         /* Integer with octal prefix, format with limited, sufficient width */
    486486        rc = sscanf("012", "%3i", &i);
    487487        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    489489}
    490490
     491/** Integer with octal prefix, format with limited, smaller width */
    491492PCUT_TEST(int_oct_smaller_width)
    492493{
     
    494495        int i;
    495496
    496         /* Integer with octal prefix, format with limited, smaller width */
    497497        rc = sscanf("012", "%2i", &i);
    498498        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    500500}
    501501
     502/** Integer with octal prefix, format with width allowing just for 0 */
    502503PCUT_TEST(int_oct_tiny_width)
    503504{
     
    505506        int i;
    506507
    507         /* Integer with octal prefix, format with width allowing just for 0 */
    508508        rc = sscanf("012", "%1i", &i);
    509509        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    511511}
    512512
     513/** Pointer */
    513514PCUT_TEST(pointer)
    514515{
     
    516517        void *ptr;
    517518
    518         /* Pointer */
    519519        rc = sscanf("0xABCDEF88", "%p", &ptr);
    520520        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    522522}
    523523
     524/** Single character */
    524525PCUT_TEST(single_char)
    525526{
     
    527528        char c;
    528529
    529         /* Single character */
    530530        rc = sscanf("x", "%c", &c);
    531531        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    533533}
    534534
     535/** Single whitespace character */
    535536PCUT_TEST(single_ws_char)
    536537{
     
    538539        char c;
    539540
    540         /* Single whitespace character */
    541541        rc = sscanf("\t", "%c", &c);
    542542        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    544544}
    545545
     546/** Multiple characters */
    546547PCUT_TEST(chars)
    547548{
     
    549550        char chars[chars_size];
    550551
    551         /* Multiple characters */
    552552        memset(chars, 'X', chars_size);
    553553        rc = sscanf("abc", "%3c", chars);
     
    559559}
    560560
     561/** Fewer characters than requested */
    561562PCUT_TEST(fewer_chars)
    562563{
     
    564565        char chars[chars_size];
    565566
    566         /* Fewer characters than requested */
    567567        memset(chars, 'X', chars_size);
    568568        rc = sscanf("abc", "%5c", chars);
     
    574574}
    575575
     576/** Reading characters but no found */
    576577PCUT_TEST(chars_not_found)
    577578{
     
    579580        char chars[chars_size];
    580581
    581         /* Reading characters but no found */
    582582        memset(chars, 'X', chars_size);
    583583        rc = sscanf("", "%5c", chars);
     
    586586}
    587587
     588/** Multiple characters with suppressed assignment */
    588589PCUT_TEST(chars_noassign)
    589590{
     
    591592        int n;
    592593
    593         /* Multiple characters with suppressed assignment */
    594594        rc = sscanf("abc", "%*3c%n", &n);
    595595        PCUT_ASSERT_INT_EQUALS(0, rc);
     
    597597}
    598598
     599/** Multiple characters with memory allocation */
    599600PCUT_TEST(chars_malloc)
    600601{
     
    602603        char *cp;
    603604
    604         /* Multiple characters with memory allocation */
    605605        cp = NULL;
    606606        rc = sscanf("abc", "%m3c", &cp);
     
    613613}
    614614
     615/** String of non-whitespace characters, unlimited width */
    615616PCUT_TEST(str)
    616617{
     
    618619        char chars[chars_size];
    619620
    620         /* String of non-whitespace characters, unlimited width */
    621621        memset(chars, 'X', chars_size);
    622622        rc = sscanf(" abc d", "%s", chars);
     
    629629}
    630630
     631/** String of non-whitespace characters, until the end */
    631632PCUT_TEST(str_till_end)
    632633{
     
    634635        char chars[chars_size];
    635636
    636         /* String of non-whitespace characters, until the end */
    637637        memset(chars, 'X', chars_size);
    638638        rc = sscanf(" abc", "%s", chars);
     
    645645}
    646646
     647/** String of non-whitespace characters, large enough width */
    647648PCUT_TEST(str_large_width)
    648649{
     
    650651        char chars[chars_size];
    651652
    652         /* String of non-whitespace characters, large enough width */
    653653        memset(chars, 'X', chars_size);
    654654        rc = sscanf(" abc d", "%5s", chars);
     
    661661}
    662662
     663/** Want string of non-whitespace, but got only whitespace */
    663664PCUT_TEST(str_not_found)
    664665{
     
    666667        char chars[chars_size];
    667668
    668         /* Want string of non-whitespace, but got only whitespace */
    669669        memset(chars, 'X', chars_size);
    670670        rc = sscanf(" ", "%s", chars);
     
    673673}
    674674
     675/** String of non-whitespace characters, small width */
    675676PCUT_TEST(str_small_width)
    676677{
     
    678679        char chars[chars_size];
    679680
    680         /* String of non-whitespace characters, small width */
    681681        memset(chars, 'X', chars_size);
    682682        rc = sscanf(" abc", "%2s", chars);
     
    688688}
    689689
     690/** String of non-whitespace characters, assignment suppression */
    690691PCUT_TEST(str_noassign)
    691692{
     
    693694        int n;
    694695
    695         /* String of non-whitespace characters, assignment suppression */
    696696        rc = sscanf(" abc d", "%*s%n", &n);
    697697        PCUT_ASSERT_INT_EQUALS(0, rc);
     
    699699}
    700700
     701/** String of non-whitespace characters, memory allocation */
    701702PCUT_TEST(str_malloc)
    702703{
     
    704705        char *cp;
    705706
    706         /* String of non-whitespace characters, memory allocation */
    707707        rc = sscanf(" abc d", "%ms", &cp);
    708708        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    715715}
    716716
     717/** Set conversion without width specified terminating before the end  */
    717718PCUT_TEST(set_convert)
    718719{
     
    721722        int i;
    722723
    723         /* Set conversion without width specified terminating before the end  */
    724724        memset(chars, 'X', chars_size);
    725725        rc = sscanf("abcd42", "%[abc]d%d", chars, &i);
     
    733733}
    734734
     735/** Set conversion without width specified, until the end */
    735736PCUT_TEST(set_till_end)
    736737{
     
    738739        char chars[chars_size];
    739740
    740         /* Set conversion without width specified, until the end */
    741741        memset(chars, 'X', chars_size);
    742742        rc = sscanf("abc", "%[abc]", chars);
     
    749749}
    750750
     751/** Set conversion with larger width */
    751752PCUT_TEST(set_large_width)
    752753{
     
    754755        char chars[chars_size];
    755756
    756         /* Set conversion with larger width */
    757757        memset(chars, 'X', chars_size);
    758758        rc = sscanf("abcd", "%5[abc]", chars);
     
    765765}
    766766
     767/** Set conversion with smaller width */
    767768PCUT_TEST(set_small_width)
    768769{
     
    770771        char chars[chars_size];
    771772
    772         /* Set conversion with smaller width */
    773773        memset(chars, 'X', chars_size);
    774774        rc = sscanf("abcd", "%3[abcd]", chars);
     
    781781}
    782782
     783/** Set conversion with negated scanset */
    783784PCUT_TEST(set_inverted)
    784785{
     
    786787        char chars[chars_size];
    787788
    788         /* Set conversion with negated scanset */
    789789        memset(chars, 'X', chars_size);
    790790        rc = sscanf("abcd", "%[^d]", chars);
     
    797797}
    798798
     799/** Set conversion with ']' in scanset */
    799800PCUT_TEST(set_with_rbr)
    800801{
     
    802803        char chars[chars_size];
    803804
    804         /* Set conversion with ']' in scanset */
    805805        memset(chars, 'X', chars_size);
    806806        rc = sscanf("]bcd", "%[]bc]", chars);
     
    813813}
    814814
     815/** Set conversion with ']' in inverted scanset */
    815816PCUT_TEST(set_inverted_with_rbr)
    816817{
     
    818819        char chars[chars_size];
    819820
    820         /* Set conversion with ']' in inverted scanset */
    821821        memset(chars, 'X', chars_size);
    822822        rc = sscanf("abc]", "%[^]def]", chars);
     
    829829}
    830830
     831/** Set conversion with leading '-' in scanset */
    831832PCUT_TEST(set_with_leading_dash)
    832833{
     
    834835        char chars[chars_size];
    835836
    836         /* Set conversion with leading '-' in scanset */
    837837        memset(chars, 'X', chars_size);
    838838        rc = sscanf("a-bc[", "%[-abc]", chars);
     
    846846}
    847847
     848/** Set conversion with trailing '-' in scanset */
    848849PCUT_TEST(set_with_trailing_dash)
    849850{
     
    851852        char chars[chars_size];
    852853
    853         /* Set conversion with trailing '-' in scanset */
    854854        memset(chars, 'X', chars_size);
    855855        rc = sscanf("a-bc]", "%[abc-]", chars);
     
    863863}
    864864
     865/** Set conversion with leading '-' in inverted scanset */
    865866PCUT_TEST(set_inverted_with_leading_dash)
    866867{
     
    868869        char chars[chars_size];
    869870
    870         /* Set conversion with leading '-' in inverted scanset */
    871871        memset(chars, 'X', chars_size);
    872872        rc = sscanf("def-", "%[^-abc]", chars);
     
    879879}
    880880
     881/** ']' after '^' in scanset does not lose meaning of scanset delimiter */
    881882PCUT_TEST(set_inverted_with_only_dash)
    882883{
     
    884885        char chars[chars_size];
    885886
    886         /*
    887          * ']' after '^' in scanset does not lose meaning of scanset
    888          * delimiter
    889          */
    890887        memset(chars, 'X', chars_size);
    891888        rc = sscanf("abc-", "%[^-]", chars);
     
    898895}
    899896
     897/** '^' after '-' in scanset does not have special meaning */
    900898PCUT_TEST(set_inverted_with_dash_caret)
    901899{
     
    903901        char chars[chars_size];
    904902
    905         /* '^' after '-' in scanset does not have special meaning */
    906903        memset(chars, 'X', chars_size);
    907904        rc = sscanf("-^a", "%[-^a]", chars);
     
    914911}
    915912
     913/** Set conversion with range (GNU extension) */
     914PCUT_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 */
     930PCUT_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 */
    916946PCUT_TEST(set_noassign)
    917947{
     
    919949        int n;
    920950
    921         /* Set conversion with assignment suppression */
    922951        rc = sscanf("abcd42", "%*[abc]%n", &n);
    923952        PCUT_ASSERT_INT_EQUALS(0, rc);
     
    925954}
    926955
     956/** Set conversion with memory allocation */
    927957PCUT_TEST(set_malloc)
    928958{
     
    930960        char *cp;
    931961
    932         /* Set conversion with memory allocation */
    933962        cp = NULL;
    934963        rc = sscanf("abcd42", "%m[abcd]", &cp);
     
    943972}
    944973
     974/** Decimal integer with suppressed assignment */
    945975PCUT_TEST(dec_int_noassign)
    946976{
     
    948978        int n;
    949979
    950         /* Decimal integer with suppressed assignment */
    951980        rc = sscanf("42", "%*d%n", &n);
    952981        PCUT_ASSERT_INT_EQUALS(0, rc);
     
    954983}
    955984
     985/** Count of characters read */
    956986PCUT_TEST(count_chars)
    957987{
     
    960990        int n;
    961991
    962         /* Count of characters read */
    963992        memset(chars, 'X', chars_size);
    964993        rc = sscanf("abcd", "%3c%n", chars, &n);
     
    9711000}
    9721001
     1002/** Float with just integer part */
    9731003PCUT_TEST(float_intpart_only)
    9741004{
     
    9761006        float f;
    9771007
    978         /* Float with just integer part */
    9791008        rc = sscanf("42", "%f", &f);
    9801009        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    9821011}
    9831012
     1013/** Double with just integer part */
    9841014PCUT_TEST(double_intpart_only)
    9851015{
     
    9871017        double d;
    9881018
    989         /* Double with just integer part */
    9901019        rc = sscanf("42", "%lf", &d);
    9911020        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    9931022}
    9941023
     1024/** Long double with just integer part */
    9951025PCUT_TEST(ldouble_intpart_only)
    9961026{
     
    9981028        long double ld;
    9991029
    1000         /* Long double with just integer part */
    10011030        rc = sscanf("42", "%Lf", &ld);
    10021031        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10041033}
    10051034
     1035/** Float with just hexadecimal integer part */
    10061036PCUT_TEST(float_hex_intpart_only)
    10071037{
     
    10091039        float f;
    10101040
    1011         /* Float with just hexadecimal integer part */
    10121041        rc = sscanf("0x2a", "%f", &f);
    10131042        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10151044}
    10161045
     1046/** Float with sign and integer part */
    10171047PCUT_TEST(float_sign_intpart)
    10181048{
     
    10201050        float f;
    10211051
    1022         /* Float with sign and integer part */
    10231052        rc = sscanf("-42", "%f", &f);
    10241053        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10261055}
    10271056
     1057/** Float with integer and fractional part */
    10281058PCUT_TEST(float_intpart_fract)
    10291059{
     
    10311061        float f;
    10321062
    1033         /* Float with integer and fractional part */
    10341063        rc = sscanf("4.2", "%f", &f);
    10351064        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10391068}
    10401069
     1070/** Float with integer part and unsigned exponent */
    10411071PCUT_TEST(float_intpart_exp)
    10421072{
     
    10441074        float f;
    10451075
    1046         /* Float with integer part and unsigned exponent */
    10471076        rc = sscanf("42e1", "%f", &f);
    10481077        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10501079}
    10511080
     1081
     1082/** Float with integer part and positive exponent */
    10521083PCUT_TEST(float_intpart_posexp)
    10531084{
    10541085        int rc;
    10551086        float f;
    1056 
    1057         /* Float with integer part and positive exponent */
    10581087        rc = sscanf("42e+1", "%f", &f);
    10591088        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10611090}
    10621091
     1092/** Float with integer part and negative exponent */
    10631093PCUT_TEST(float_intpart_negexp)
    10641094{
     
    10661096        float f;
    10671097
    1068         /* Float with integer part and negative exponent */
    10691098        rc = sscanf("42e-1", "%f", &f);
    10701099        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10741103}
    10751104
     1105/** Float with integer, fractional parts and unsigned exponent */
    10761106PCUT_TEST(float_intpart_fract_exp)
    10771107{
     
    10791109        float f;
    10801110
    1081         /* Float with integer, fractional parts and unsigned exponent */
    10821111        rc = sscanf("4.2e1", "%f", &f);
    10831112        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10851114}
    10861115
     1116/** Hexadecimal float with integer and fractional part */
    10871117PCUT_TEST(hexfloat_intpart_fract)
    10881118{
     
    10901120        float f;
    10911121
    1092         /* Hexadecimal float with integer and fractional part */
    10931122        rc = sscanf("0x2.a", "%f", &f);
    10941123        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    10961125}
    10971126
     1127/** Hexadecimal float with integer part and unsigned exponent */
    10981128PCUT_TEST(hexfloat_intpart_exp)
    10991129{
     
    11011131        float f;
    11021132
    1103         /*
    1104          * Hexadecimal float with integer part and unsigned exponent
    1105          */
    11061133        rc = sscanf("0x2ap1", "%f", &f);
    11071134        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11091136}
    11101137
     1138/** Hexadecimal float with integer part and negative exponent */
    11111139PCUT_TEST(hexfloat_intpart_negexp)
    11121140{
     
    11141142        float f;
    11151143
    1116         /*
    1117          * Hexadecimal float with integer part and negative exponent
    1118          */
    11191144        rc = sscanf("0x2ap-1", "%f", &f);
    11201145        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11221147}
    11231148
     1149/** Hexadecimal float with integer, fractional parts and unsigned exponent */
    11241150PCUT_TEST(hexfloat_intpart_fract_exp)
    11251151{
     
    11271153        float f;
    11281154
    1129         /*
    1130          * Hexadecimal float with integer, fractional parts and unsigned
    1131          * exponent
    1132          */
    11331155        rc = sscanf("0x2.ap4", "%f", &f);
    11341156        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11361158}
    11371159
     1160/** Float with just integer part and limited width */
    11381161PCUT_TEST(float_intpart_limwidth)
    11391162{
     
    11411164        float f;
    11421165
    1143         /* Float with just integer part and limited width */
    11441166        rc = sscanf("1234", "%3f", &f);
    11451167        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11471169}
    11481170
     1171/** Float with integer, fractional part and limited width */
    11491172PCUT_TEST(float_intpart_fract_limwidth)
    11501173{
     
    11521175        float f;
    11531176
    1154         /* Float with integer, fractional part and limited width */
    11551177        rc = sscanf("12.34", "%4f", &f);
    11561178        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11601182}
    11611183
     1184/** Float with width only enough to cover an integral part */
    11621185PCUT_TEST(float_width_for_only_intpart)
    11631186{
     
    11651188        float f;
    11661189
    1167         /* Float with width only enough to cover an integral part */
    11681190        rc = sscanf("12.34", "%3f", &f);
    11691191        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11711193}
    11721194
     1195/** Float with width too small to cover the exponent number */
    11731196PCUT_TEST(float_width_small_for_expnum)
    11741197{
     
    11761199        float f;
    11771200
    1178         /* Float with width too small to cover the exponent number */
    11791201        rc = sscanf("12.34e+2", "%7f", &f);
    11801202        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11841206}
    11851207
     1208/** Float with width too small to cover the exponent sign and number */
    11861209PCUT_TEST(float_width_small_for_expsignum)
    11871210{
     
    11891212        float f;
    11901213
    1191         /* Float with width too small to cover the exponent sign and number */
    11921214        rc = sscanf("12.34e+2", "%6f", &f);
    11931215        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    11971219}
    11981220
     1221/** Float with width too small to cover the exponent part */
    11991222PCUT_TEST(float_width_small_for_exp)
    12001223{
     
    12021225        float f;
    12031226
    1204         /* Float with width too small to cover the exponent part */
    12051227        rc = sscanf("12.34e+2", "%5f", &f);
    12061228        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12101232}
    12111233
     1234/** Float using alternate form 'F' */
    12121235PCUT_TEST(float_cap_f)
    12131236{
     
    12151238        float f;
    12161239
    1217         /* Float using alternate form 'F' */
    12181240        rc = sscanf("42e1", "%F", &f);
    12191241        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12211243}
    12221244
     1245/** Float using alternate form 'a' */
    12231246PCUT_TEST(float_a)
    12241247{
     
    12261249        float f;
    12271250
    1228         /* Float using alternate form 'a' */
    12291251        rc = sscanf("42e1", "%a", &f);
    12301252        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12321254}
    12331255
     1256/** Float using alternate form 'e' */
    12341257PCUT_TEST(float_e)
    12351258{
     
    12371260        float f;
    12381261
    1239         /* Float using alternate form 'e' */
    12401262        rc = sscanf("42e1", "%e", &f);
    12411263        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12431265}
    12441266
     1267/** Float using alternate form 'g' */
    12451268PCUT_TEST(float_g)
    12461269{
     
    12481271        float f;
    12491272
    1250         /* Float using alternate form 'g' */
    12511273        rc = sscanf("42e1", "%g", &f);
    12521274        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12541276}
    12551277
     1278/** Float using alternate form 'A' */
    12561279PCUT_TEST(float_cap_a)
    12571280{
     
    12591282        float f;
    12601283
    1261         /* Float using alternate form 'A' */
    12621284        rc = sscanf("42e1", "%A", &f);
    12631285        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12651287}
    12661288
     1289/** Float using alternate form 'E' */
    12671290PCUT_TEST(float_cap_e)
    12681291{
     
    12701293        float f;
    12711294
    1272         /* Float using alternate form 'E' */
    12731295        rc = sscanf("42e1", "%E", &f);
    12741296        PCUT_ASSERT_INT_EQUALS(1, rc);
     
    12761298}
    12771299
     1300/** Float using alternate form 'G' */
    12781301PCUT_TEST(float_cap_g)
    12791302{
     
    12811304        float f;
    12821305
    1283         /* Float using alternate form 'G' */
    12841306        rc = sscanf("42e1", "%G", &f);
    12851307        PCUT_ASSERT_INT_EQUALS(1, rc);
Note: See TracChangeset for help on using the changeset viewer.