From 95cef39defe9af5b8cdb78fa9d0e543dae0ed5dd Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 21 Aug 2008 05:19:40 +0000 Subject: Test case 557 now also verifies signed and unsigned int formatting. --- configure.ac | 1 + tests/data/test557 | 2 + tests/libtest/lib557.c | 399 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+) diff --git a/configure.ac b/configure.ac index 76ccb8829..76680517f 100644 --- a/configure.ac +++ b/configure.ac @@ -1995,6 +1995,7 @@ CURL_CHECK_STRUCT_TIMEVAL CURL_VERIFY_RUNTIMELIBS AC_CHECK_SIZEOF(size_t) +AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) CURL_CONFIGURE_LONG AC_CHECK_SIZEOF(time_t) diff --git a/tests/data/test557 b/tests/data/test557 index b493a49cd..0929e0ac5 100644 --- a/tests/data/test557 +++ b/tests/data/test557 @@ -26,6 +26,8 @@ nothing # Verify data after the test has been "shot" +All curl_mprintf() unsigned int tests OK! +All curl_mprintf() signed int tests OK! All curl_mprintf() unsigned long tests OK! All curl_mprintf() signed long tests OK! All curl_mprintf() curl_off_t tests OK! diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index c70155e95..57061a759 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -35,11 +35,27 @@ int curl_msprintf(char *buffer, const char *format, ...); #define BUFSZ 256 +#define UINT_TESTS_ARRSZ 1 + 100 +#define SINT_TESTS_ARRSZ 1 + 100 #define ULONG_TESTS_ARRSZ 1 + 100 #define SLONG_TESTS_ARRSZ 1 + 100 #define COFFT_TESTS_ARRSZ 1 + 100 +struct unsint_st { + unsigned int num; /* unsigned int */ + const char *expected; /* expected string */ + char result[BUFSZ]; /* result string */ +}; + + +struct sigint_st { + int num; /* signed int */ + const char *expected; /* expected string */ + char result[BUFSZ]; /* result string */ +}; + + struct unslong_st { unsigned long num; /* unsigned long */ const char *expected; /* expected string */ @@ -61,11 +77,390 @@ struct curloff_st { }; +static struct unsint_st ui_test[UINT_TESTS_ARRSZ]; +static struct sigint_st si_test[SINT_TESTS_ARRSZ]; static struct unslong_st ul_test[ULONG_TESTS_ARRSZ]; static struct siglong_st sl_test[SLONG_TESTS_ARRSZ]; static struct curloff_st co_test[COFFT_TESTS_ARRSZ]; +static int test_unsigned_int_formatting(void) +{ + int i, j; + int num_uint_tests; + int failed = 0; + +#if (SIZEOF_INT == 2) + + i=1; ui_test[i].num = 0xFFFFU; ui_test[i].expected = "65535"; + i++; ui_test[i].num = 0xFF00U; ui_test[i].expected = "65280"; + i++; ui_test[i].num = 0x00FFU; ui_test[i].expected = "255"; + + i++; ui_test[i].num = 0xF000U; ui_test[i].expected = "61440"; + i++; ui_test[i].num = 0x0F00U; ui_test[i].expected = "3840"; + i++; ui_test[i].num = 0x00F0U; ui_test[i].expected = "240"; + i++; ui_test[i].num = 0x000FU; ui_test[i].expected = "15"; + + i++; ui_test[i].num = 0xC000U; ui_test[i].expected = "49152"; + i++; ui_test[i].num = 0x0C00U; ui_test[i].expected = "3072"; + i++; ui_test[i].num = 0x00C0U; ui_test[i].expected = "192"; + i++; ui_test[i].num = 0x000CU; ui_test[i].expected = "12"; + + i++; ui_test[i].num = 0x0001U; ui_test[i].expected = "1"; + i++; ui_test[i].num = 0x0000U; ui_test[i].expected = "0"; + + num_uint_tests = i; + +#elif (SIZEOF_INT == 4) + + i=1; ui_test[i].num = 0xFFFFFFFFU; ui_test[i].expected = "4294967295"; + i++; ui_test[i].num = 0xFFFF0000U; ui_test[i].expected = "4294901760"; + i++; ui_test[i].num = 0x0000FFFFU; ui_test[i].expected = "65535"; + + i++; ui_test[i].num = 0xFF000000U; ui_test[i].expected = "4278190080"; + i++; ui_test[i].num = 0x00FF0000U; ui_test[i].expected = "16711680"; + i++; ui_test[i].num = 0x0000FF00U; ui_test[i].expected = "65280"; + i++; ui_test[i].num = 0x000000FFU; ui_test[i].expected = "255"; + + i++; ui_test[i].num = 0xF0000000U; ui_test[i].expected = "4026531840"; + i++; ui_test[i].num = 0x0F000000U; ui_test[i].expected = "251658240"; + i++; ui_test[i].num = 0x00F00000U; ui_test[i].expected = "15728640"; + i++; ui_test[i].num = 0x000F0000U; ui_test[i].expected = "983040"; + i++; ui_test[i].num = 0x0000F000U; ui_test[i].expected = "61440"; + i++; ui_test[i].num = 0x00000F00U; ui_test[i].expected = "3840"; + i++; ui_test[i].num = 0x000000F0U; ui_test[i].expected = "240"; + i++; ui_test[i].num = 0x0000000FU; ui_test[i].expected = "15"; + + i++; ui_test[i].num = 0xC0000000U; ui_test[i].expected = "3221225472"; + i++; ui_test[i].num = 0x0C000000U; ui_test[i].expected = "201326592"; + i++; ui_test[i].num = 0x00C00000U; ui_test[i].expected = "12582912"; + i++; ui_test[i].num = 0x000C0000U; ui_test[i].expected = "786432"; + i++; ui_test[i].num = 0x0000C000U; ui_test[i].expected = "49152"; + i++; ui_test[i].num = 0x00000C00U; ui_test[i].expected = "3072"; + i++; ui_test[i].num = 0x000000C0U; ui_test[i].expected = "192"; + i++; ui_test[i].num = 0x0000000CU; ui_test[i].expected = "12"; + + i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1"; + i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0"; + + num_uint_tests = i; + +#elif (SIZEOF_INT == 8) + + i=1; ui_test[i].num = 0xFFFFFFFFFFFFFFFFU; ui_test[i].expected = "18446744073709551615"; + i++; ui_test[i].num = 0xFFFFFFFF00000000U; ui_test[i].expected = "18446744069414584320"; + i++; ui_test[i].num = 0x00000000FFFFFFFFU; ui_test[i].expected = "4294967295"; + + i++; ui_test[i].num = 0xFFFF000000000000U; ui_test[i].expected = "18446462598732840960"; + i++; ui_test[i].num = 0x0000FFFF00000000U; ui_test[i].expected = "281470681743360"; + i++; ui_test[i].num = 0x00000000FFFF0000U; ui_test[i].expected = "4294901760"; + i++; ui_test[i].num = 0x000000000000FFFFU; ui_test[i].expected = "65535"; + + i++; ui_test[i].num = 0xFF00000000000000U; ui_test[i].expected = "18374686479671623680"; + i++; ui_test[i].num = 0x00FF000000000000U; ui_test[i].expected = "71776119061217280"; + i++; ui_test[i].num = 0x0000FF0000000000U; ui_test[i].expected = "280375465082880"; + i++; ui_test[i].num = 0x000000FF00000000U; ui_test[i].expected = "1095216660480"; + i++; ui_test[i].num = 0x00000000FF000000U; ui_test[i].expected = "4278190080"; + i++; ui_test[i].num = 0x0000000000FF0000U; ui_test[i].expected = "16711680"; + i++; ui_test[i].num = 0x000000000000FF00U; ui_test[i].expected = "65280"; + i++; ui_test[i].num = 0x00000000000000FFU; ui_test[i].expected = "255"; + + i++; ui_test[i].num = 0xF000000000000000U; ui_test[i].expected = "17293822569102704640"; + i++; ui_test[i].num = 0x0F00000000000000U; ui_test[i].expected = "1080863910568919040"; + i++; ui_test[i].num = 0x00F0000000000000U; ui_test[i].expected = "67553994410557440"; + i++; ui_test[i].num = 0x000F000000000000U; ui_test[i].expected = "4222124650659840"; + i++; ui_test[i].num = 0x0000F00000000000U; ui_test[i].expected = "263882790666240"; + i++; ui_test[i].num = 0x00000F0000000000U; ui_test[i].expected = "16492674416640"; + i++; ui_test[i].num = 0x000000F000000000U; ui_test[i].expected = "1030792151040"; + i++; ui_test[i].num = 0x0000000F00000000U; ui_test[i].expected = "64424509440"; + i++; ui_test[i].num = 0x00000000F0000000U; ui_test[i].expected = "4026531840"; + i++; ui_test[i].num = 0x000000000F000000U; ui_test[i].expected = "251658240"; + i++; ui_test[i].num = 0x0000000000F00000U; ui_test[i].expected = "15728640"; + i++; ui_test[i].num = 0x00000000000F0000U; ui_test[i].expected = "983040"; + i++; ui_test[i].num = 0x000000000000F000U; ui_test[i].expected = "61440"; + i++; ui_test[i].num = 0x0000000000000F00U; ui_test[i].expected = "3840"; + i++; ui_test[i].num = 0x00000000000000F0U; ui_test[i].expected = "240"; + i++; ui_test[i].num = 0x000000000000000FU; ui_test[i].expected = "15"; + + i++; ui_test[i].num = 0xC000000000000000U; ui_test[i].expected = "13835058055282163712"; + i++; ui_test[i].num = 0x0C00000000000000U; ui_test[i].expected = "864691128455135232"; + i++; ui_test[i].num = 0x00C0000000000000U; ui_test[i].expected = "54043195528445952"; + i++; ui_test[i].num = 0x000C000000000000U; ui_test[i].expected = "3377699720527872"; + i++; ui_test[i].num = 0x0000C00000000000U; ui_test[i].expected = "211106232532992"; + i++; ui_test[i].num = 0x00000C0000000000U; ui_test[i].expected = "13194139533312"; + i++; ui_test[i].num = 0x000000C000000000U; ui_test[i].expected = "824633720832"; + i++; ui_test[i].num = 0x0000000C00000000U; ui_test[i].expected = "51539607552"; + i++; ui_test[i].num = 0x00000000C0000000U; ui_test[i].expected = "3221225472"; + i++; ui_test[i].num = 0x000000000C000000U; ui_test[i].expected = "201326592"; + i++; ui_test[i].num = 0x0000000000C00000U; ui_test[i].expected = "12582912"; + i++; ui_test[i].num = 0x00000000000C0000U; ui_test[i].expected = "786432"; + i++; ui_test[i].num = 0x000000000000C000U; ui_test[i].expected = "49152"; + i++; ui_test[i].num = 0x0000000000000C00U; ui_test[i].expected = "3072"; + i++; ui_test[i].num = 0x00000000000000C0U; ui_test[i].expected = "192"; + i++; ui_test[i].num = 0x000000000000000CU; ui_test[i].expected = "12"; + + i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1"; + i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0"; + + num_uint_tests = i; + +#endif + + for(i=1; i<=num_uint_tests; i++) { + + for(j=0; j