// S : tags libc c // S : expect --result valid // S : cc -o test.bc -D_PDCLIB_BUILD -DTEST $file // S : verify -o nofail:malloc test.bc #include #include #include #include #include "_PDCLIB_test.h" #include int main( void ) { #ifndef REGTEST const char * p; char test[] = "123_"; char fail[] = "xxx"; char sign = '-'; /* basic functionality */ p = test; errno = 0; TESTCASE( _PDCLIB_strtox_main( &p, 10u, (uintmax_t)999, (uintmax_t)12, 3, &sign ) == 123 ); TESTCASE( errno == 0 ); TESTCASE( p == &test[3] ); /* proper functioning to smaller base */ p = test; TESTCASE( _PDCLIB_strtox_main( &p, 8u, (uintmax_t)999, (uintmax_t)12, 3, &sign ) == 0123 ); TESTCASE( errno == 0 ); TESTCASE( p == &test[3] ); /* overflowing subject sequence must still return proper endptr */ p = test; TESTCASE( _PDCLIB_strtox_main( &p, 4u, (uintmax_t)999, (uintmax_t)1, 2, &sign ) == 999 ); TESTCASE( errno == ERANGE ); TESTCASE( p == &test[3] ); TESTCASE( sign == '+' ); /* testing conversion failure */ errno = 0; p = fail; sign = '-'; TESTCASE( _PDCLIB_strtox_main( &p, 10u, (uintmax_t)999, (uintmax_t)99, 8, &sign ) == 0 ); TESTCASE( p == NULL ); #endif return TEST_RESULTS; }