]> pd.if.org Git - pdclib/commitdiff
Extended test drivers to cover sign error.
authorsolar <unknown>
Wed, 23 Jun 2010 08:28:28 +0000 (08:28 +0000)
committersolar <unknown>
Wed, 23 Jun 2010 08:28:28 +0000 (08:28 +0000)
functions/inttypes/strtoimax.c
functions/inttypes/strtoumax.c
functions/stdlib/strtol.c
functions/stdlib/strtoll.c
functions/stdlib/strtoul.c
functions/stdlib/strtoull.c
internals/_PDCLIB_int.h

index af29d3df999acf685d85503bd51509ce88358459..936389cbb97f8fd3392714cf1939117a8098568d 100755 (executable)
@@ -26,7 +26,6 @@ intmax_t strtoimax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict
     else
     {
         /* FIXME: This breaks on some machines that round negatives wrongly */
-        /* FIXME: Sign error not caught by testdriver */
         rc = (intmax_t)_PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)INTMAX_MIN, (uintmax_t)( INTMAX_MIN / -base ), (int)( -( INTMAX_MIN % base ) ), &sign );
     }
     if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) nptr;
@@ -91,34 +90,34 @@ int main( void )
     errno = 0;
 #if INTMAX_MAX == 0x7fffffffffffffffLL
     /* testing "even" overflow, i.e. base is power of two */
-    TESTCASE( strtoimax( "0x7FFFFFFFFFFFFFFF", NULL, 0 ) == 0x7fffffffffffffff );
+    TESTCASE( strtoimax( "9223372036854775807", NULL, 0 ) == INTMAX_MAX );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "0x8000000000000000", NULL, 0 ) == INTMAX_MAX );
+    TESTCASE( strtoimax( "9223372036854775808", NULL, 0 ) == INTMAX_MAX );
     TESTCASE( errno == ERANGE );
     errno = 0;
-    TESTCASE( strtoimax( "-0x7FFFFFFFFFFFFFFF", NULL, 0 ) == (long long)0x8000000000000001 );
+    TESTCASE( strtoimax( "-9223372036854775807", NULL, 0 ) == (INTMAX_MIN + 1) );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "-0x8000000000000000", NULL, 0 ) == INTMAX_MIN );
+    TESTCASE( strtoimax( "-9223372036854775808", NULL, 0 ) == INTMAX_MIN );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "-0x8000000000000001", NULL, 0 ) == INTMAX_MIN );
+    TESTCASE( strtoimax( "-9223372036854775809", NULL, 0 ) == INTMAX_MIN );
     TESTCASE( errno == ERANGE );
     /* TODO: test "odd" overflow, i.e. base is not power of two */
-#elif INTMAX_MAX == 0x7fffffffffffffffffffffffffffffffLL
+#elif LLONG_MAX == 0x7fffffffffffffffffffffffffffffffLL
     /* testing "even" overflow, i.e. base is power of two */
-    TESTCASE( strtoimax( "0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0 ) == 0x7fffffffffffffffffffffffffffffff );
+    TESTCASE( strtoimax( "170141183460469231731687303715884105728", NULL, 0 ) == INTMAX_MAX );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MAX );
+    TESTCASE( strtoimax( "170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MAX );
     TESTCASE( errno == ERANGE );
     errno = 0;
-    TESTCASE( strtoimax( "-0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0 ) == -0x80000000000000000000000000000001 );
+    TESTCASE( strtoimax( "-170141183460469231731687303715884105728", NULL, 0 ) == (INTMAX_MIN + 1) );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "-0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MIN );
+    TESTCASE( strtoimax( "-170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MIN );
     TESTCASE( errno == 0 );
-    TESTCASE( strtoimax( "-0x80000000000000000000000000000001", NULL, 0 ) == INTMAX_MIN );
+    TESTCASE( strtoimax( "-170141183460469231731687303715884105730", NULL, 0 ) == INTMAX_MIN );
     TESTCASE( errno == ERANGE );
     /* TODO: test "odd" overflow, i.e. base is not power of two */
 #else
-#error Unsupported width of 'long long' (neither 64 nor 128 bit).
+#error Unsupported width of 'intmax_t' (neither 64 nor 128 bit).
 #endif
     return TEST_RESULTS;
 }
index 063e7ab681138c18d7c4e1055a8742181be7902d..0da7ec2889f31fffb2f510287e61a5d8dd5ad30c 100755 (executable)
@@ -75,6 +75,24 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtoumax( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
+    errno = 0;
+#if UINTMAX_MAX == 0xffffffffffffffffLL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoumax( "18446744073709551615", NULL, 0 ) == UINTMAX_MAX );
+    TESTCASE( errno == 0 );
+    TESTCASE( strtoumax( "18446744073709551616", NULL, 0 ) == UINTMAX_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#elif UINTMAX_MAX == 0xffffffffffffffffffffffffffffffffLL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoumax( "340282366920938463463374607431768211455", NULL, 0 ) == UINTMAX_MAX );
+    TESTCASE( errno == 0 );
+    TESTCASE( strtoumax( "340282366920938463463374607431768211456", NULL, 0 ) == UINTMAX_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#else
+#error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit).
+#endif
     return TEST_RESULTS;
 }
 
index ff5aa8b0cb791609f0bbe526248fd54d135b0825..085abbb612c074fcfcdf3595a29a216914718a9a 100644 (file)
@@ -84,9 +84,9 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtol( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
-    /* These tests assume two-complement, but conversion should work for   */
-    /* one-complement and signed magnitude just as well. Anyone having a   */
-    /* platform to test this on?                                           */
+    /* TODO: These tests assume two-complement, but conversion should work */
+    /* for one-complement and signed magnitude just as well. Anyone having */
+    /* a platform to test this on?                                         */
     errno = 0;
 #if LONG_MAX == 0x7fffffffL
     /* testing "even" overflow, i.e. base is power of two */
index 13a1a1de6cf609b27784b0b1262dd9bb76102d8f..b4476915b0a6b7c29fff1c17a8d8fa694746d01f 100644 (file)
@@ -84,9 +84,9 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtoll( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
-    /* These tests assume two-complement, but conversion should work for   */
-    /* one-complement and signed magnitude just as well. Anyone having a   */
-    /* platform to test this on?                                           */
+    /* TODO: These tests assume two-complement, but conversion should work */
+    /* for one-complement and signed magnitude just as well. Anyone having */
+    /* a platform to test this on?                                         */
     errno = 0;
 #if LLONG_MAX == 0x7fffffffffffffffLL
     /* testing "even" overflow, i.e. base is power of two */
index 4aefc4f08785c6b6dd934f6abfdf9efa0907d8ee..568029756b69af9267be04b790ad5a086f0ba4bc 100644 (file)
@@ -75,6 +75,29 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtoul( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
+    /* TODO: These tests assume two-complement, but conversion should work */
+    /* for one-complement and signed magnitude just as well. Anyone having */
+    /* a platform to test this on?                                         */
+    errno = 0;
+#if ULONG_MAX == 0xffffffffL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoul( "4294967295", NULL, 0 ) == ULONG_MAX );
+    TESTCASE( errno == 0 );
+    errno = 0;
+    TESTCASE( strtoul( "4294967296", NULL, 0 ) == ULONG_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#elif ULONG_MAX == 0xffffffffffffffffL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoul( "18446744073709551615", NULL, 0 ) == ULONG_MAX );
+    TESTCASE( errno == 0 );
+    errno = 0;
+    TESTCASE( strtoul( "18446744073709551616", NULL, 0 ) == ULONG_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#else
+#error Unsupported width of 'long' (neither 32 nor 64 bit).
+#endif
     return TEST_RESULTS;
 }
 
index a65779cfadd6be34fab012fca92f753d328aa736..ca9dd1936ee2fb46c11dddfaf5f424aa5147e3bb 100644 (file)
@@ -75,6 +75,24 @@ int main( void )
     endptr = NULL;
     TESTCASE( strtoull( overflow, &endptr, 0 ) == 0 );
     TESTCASE( endptr == overflow );
+    errno = 0;
+#if ULLONG_MAX == 0xffffffffffffffffLL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoull( "18446744073709551615", NULL, 0 ) == ULLONG_MAX );
+    TESTCASE( errno == 0 );
+    TESTCASE( strtoull( "18446744073709551616", NULL, 0 ) == ULLONG_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#elif ULLONG_MAX == 0xffffffffffffffffffffffffffffffffLL
+    /* testing "even" overflow, i.e. base is power of two */
+    TESTCASE( strtoull( "340282366920938463463374607431768211455", NULL, 0 ) == ULLONG_MAX );
+    TESTCASE( errno == 0 );
+    TESTCASE( strtoull( "340282366920938463463374607431768211456", NULL, 0 ) == ULLONG_MAX );
+    TESTCASE( errno == ERANGE );
+    /* TODO: test "odd" overflow, i.e. base is not power of two */
+#else
+#error Unsupported width of 'long long' (neither 64 nor 128 bit).
+#endif
     return TEST_RESULTS;
 }
 
index f6fedd16405b0090d351a81d5dab7da123d10a02..2420c790e7dc3071ae088bb9ff84c1386f2fedc8 100644 (file)
 #elif _PDCLIB_LLONG_BYTES  == 16
 #define _PDCLIB_LLONG_MAX  0x7fffffffffffffffffffffffffffffffLL
 #define _PDCLIB_LLONG_MIN  (-0x7fffffffffffffffffffffffffffffffLL - 1LL)
-#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffLL
+#define _PDCLIB_ULLONG_MAX 0xffffffffffffffffffffffffffffffffULL
 #else
 #error Unsupported width of 'long long' (neither 64 nor 128 bit).
 #endif