Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/test/strtol.c

    r1c9bf292 ra4e78743  
    3838#include <stdlib.h>
    3939#include <str.h>
    40 #include <limits.h>
    4140
    4241PCUT_INIT;
     
    218217        /* Correct result. */
    219218        PCUT_ASSERT_INT_EQUALS(EOVERFLOW, rc);
     219        PCUT_ASSERT_UINT_EQUALS(UINT64_MAX, result);
    220220#endif
    221221
     
    245245        /* Correct result. */
    246246        PCUT_ASSERT_INT_EQUALS(EOVERFLOW, rc);
     247        PCUT_ASSERT_UINT_EQUALS(UINT64_MAX, result);
    247248#endif
    248 }
    249 
    250 PCUT_TEST(strtoul_negative_wraparound)
    251 {
    252         long output;
    253         char *endp;
    254         char *endp_unchanged = (char *) "endp_unchanged unique pointer";
    255         int errno_unchanged = -1;
    256         const char *input;
    257         int base;
    258 
    259         /*
    260          * N2176 7.22.1.4 The strtol, strtoll, strtoul, and strtoull functions
    261          *
    262          * "If the subject sequence begins with a minus sign, the value
    263          * resulting from the conversion is negated (in the return type)."
    264          */
    265 
    266         endp = endp_unchanged;
    267         errno = errno_unchanged;
    268         output = strtoul(input = "-10", &endp, base = 0);
    269         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    270         PCUT_ASSERT_PTR_EQUALS(input + 3, endp);
    271         PCUT_ASSERT_UINT_EQUALS(-(10ul), output);
    272249}
    273250
     
    427404        endp = endp_unchanged;
    428405        errno = errno_unchanged;
    429         output = strtol(input = "    0xg", &endp, base = 0);
    430         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    431         PCUT_ASSERT_PTR_EQUALS(input + 5, endp);
    432         PCUT_ASSERT_INT_EQUALS(0, output);
    433 
    434         endp = endp_unchanged;
    435         errno = errno_unchanged;
    436406        output = strtol(input = "    0x1", &endp, base = 0);
    437407        PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
     
    448418        endp = endp_unchanged;
    449419        errno = errno_unchanged;
    450         output = strtol(input = "    0xg", &endp, base = 16);
    451         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    452         PCUT_ASSERT_PTR_EQUALS(input + 5, endp);
    453         PCUT_ASSERT_INT_EQUALS(0, output);
    454 
    455         endp = endp_unchanged;
    456         errno = errno_unchanged;
    457         output = strtol(input = "    g", &endp, base = 16);
    458         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    459         PCUT_ASSERT_PTR_EQUALS(input, endp);
    460         PCUT_ASSERT_INT_EQUALS(0, output);
    461 
    462         endp = endp_unchanged;
    463         errno = errno_unchanged;
    464420        output = strtol(input = "    0x1", &endp, base = 16);
    465421        PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    466422        PCUT_ASSERT_PTR_EQUALS(input + 7, endp);
    467423        PCUT_ASSERT_INT_EQUALS(1, output);
    468 
    469         endp = endp_unchanged;
    470         errno = errno_unchanged;
    471         output = strtol(input = "    +", &endp, base = 0);
    472         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    473         PCUT_ASSERT_PTR_EQUALS(input, endp);
    474         PCUT_ASSERT_INT_EQUALS(0, output);
    475 
    476         endp = endp_unchanged;
    477         errno = errno_unchanged;
    478         output = strtol(input = "    -", &endp, base = 0);
    479         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    480         PCUT_ASSERT_PTR_EQUALS(input, endp);
    481         PCUT_ASSERT_INT_EQUALS(0, output);
    482 
    483         endp = endp_unchanged;
    484         errno = errno_unchanged;
    485         output = strtol(input = "    +", &endp, base = 10);
    486         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    487         PCUT_ASSERT_PTR_EQUALS(input, endp);
    488         PCUT_ASSERT_INT_EQUALS(0, output);
    489 
    490         endp = endp_unchanged;
    491         errno = errno_unchanged;
    492         output = strtol(input = "    -", &endp, base = 10);
    493         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    494         PCUT_ASSERT_PTR_EQUALS(input, endp);
    495         PCUT_ASSERT_INT_EQUALS(0, output);
    496 
    497         endp = endp_unchanged;
    498         errno = errno_unchanged;
    499         output = strtol(input = "+", &endp, base = 0);
    500         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    501         PCUT_ASSERT_PTR_EQUALS(input, endp);
    502         PCUT_ASSERT_INT_EQUALS(0, output);
    503 
    504         endp = endp_unchanged;
    505         errno = errno_unchanged;
    506         output = strtol(input = "-", &endp, base = 0);
    507         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    508         PCUT_ASSERT_PTR_EQUALS(input, endp);
    509         PCUT_ASSERT_INT_EQUALS(0, output);
    510 
    511         endp = endp_unchanged;
    512         errno = errno_unchanged;
    513         output = strtol(input = "+", &endp, base = 10);
    514         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    515         PCUT_ASSERT_PTR_EQUALS(input, endp);
    516         PCUT_ASSERT_INT_EQUALS(0, output);
    517 
    518         endp = endp_unchanged;
    519         errno = errno_unchanged;
    520         output = strtol(input = "-", &endp, base = 10);
    521         PCUT_ASSERT_INT_EQUALS(errno_unchanged, errno);
    522         PCUT_ASSERT_PTR_EQUALS(input, endp);
    523         PCUT_ASSERT_INT_EQUALS(0, output);
    524424}
    525425
Note: See TracChangeset for help on using the changeset viewer.