From a9a5a8e45cf81bc3d0585ad6dd7144a4bd3a68d9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 4 Feb 2010 14:41:01 +0000 Subject: [PATCH] Modified test case 557 to additionally verify libcurl's internal curl_m*printf() functions formatting functionality when handling signed and unsigned shorts. --- tests/data/test557 | 2 + tests/libtest/lib557.c | 309 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 306 insertions(+), 5 deletions(-) diff --git a/tests/data/test557 b/tests/data/test557 index 0929e0ac55..3da67e99fc 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 short tests OK! +All curl_mprintf() signed short tests OK! All curl_mprintf() unsigned int tests OK! All curl_mprintf() signed int tests OK! All curl_mprintf() unsigned long tests OK! diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index 124cd7c2bc..c9400a60c8 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -37,6 +37,8 @@ #define BUFSZ 256 +#define USHORT_TESTS_ARRSZ 1 + 100 +#define SSHORT_TESTS_ARRSZ 1 + 100 #define UINT_TESTS_ARRSZ 1 + 100 #define SINT_TESTS_ARRSZ 1 + 100 #define ULONG_TESTS_ARRSZ 1 + 100 @@ -44,6 +46,20 @@ #define COFFT_TESTS_ARRSZ 1 + 100 +struct unsshort_st { + unsigned short num; /* unsigned short */ + const char *expected; /* expected string */ + char result[BUFSZ]; /* result string */ +}; + + +struct sigshort_st { + short num; /* signed short */ + const char *expected; /* expected string */ + char result[BUFSZ]; /* result string */ +}; + + struct unsint_st { unsigned int num; /* unsigned int */ const char *expected; /* expected string */ @@ -79,11 +95,290 @@ 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 struct unsshort_st us_test[USHORT_TESTS_ARRSZ]; +static struct sigshort_st ss_test[SSHORT_TESTS_ARRSZ]; +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_short_formatting(void) +{ + int i, j; + int num_ushort_tests; + int failed = 0; + +#if (SIZEOF_SHORT == 1) + + i=1; us_test[i].num = 0xFFU; us_test[i].expected = "256"; + i++; us_test[i].num = 0xF0U; us_test[i].expected = "240"; + i++; us_test[i].num = 0x0FU; us_test[i].expected = "15"; + + i++; us_test[i].num = 0xE0U; us_test[i].expected = "224"; + i++; us_test[i].num = 0x0EU; us_test[i].expected = "14"; + + i++; us_test[i].num = 0xC0U; us_test[i].expected = "192"; + i++; us_test[i].num = 0x0CU; us_test[i].expected = "12"; + + i++; us_test[i].num = 0x01U; us_test[i].expected = "1"; + i++; us_test[i].num = 0x00U; us_test[i].expected = "0"; + + num_ushort_tests = i; + +#elif (SIZEOF_SHORT == 2) + + i=1; us_test[i].num = 0xFFFFU; us_test[i].expected = "65535"; + i++; us_test[i].num = 0xFF00U; us_test[i].expected = "65280"; + i++; us_test[i].num = 0x00FFU; us_test[i].expected = "255"; + + i++; us_test[i].num = 0xF000U; us_test[i].expected = "61440"; + i++; us_test[i].num = 0x0F00U; us_test[i].expected = "3840"; + i++; us_test[i].num = 0x00F0U; us_test[i].expected = "240"; + i++; us_test[i].num = 0x000FU; us_test[i].expected = "15"; + + i++; us_test[i].num = 0xC000U; us_test[i].expected = "49152"; + i++; us_test[i].num = 0x0C00U; us_test[i].expected = "3072"; + i++; us_test[i].num = 0x00C0U; us_test[i].expected = "192"; + i++; us_test[i].num = 0x000CU; us_test[i].expected = "12"; + + i++; us_test[i].num = 0x0001U; us_test[i].expected = "1"; + i++; us_test[i].num = 0x0000U; us_test[i].expected = "0"; + + num_ushort_tests = i; + +#elif (SIZEOF_SHORT == 4) + + i=1; us_test[i].num = 0xFFFFFFFFU; us_test[i].expected = "4294967295"; + i++; us_test[i].num = 0xFFFF0000U; us_test[i].expected = "4294901760"; + i++; us_test[i].num = 0x0000FFFFU; us_test[i].expected = "65535"; + + i++; us_test[i].num = 0xFF000000U; us_test[i].expected = "4278190080"; + i++; us_test[i].num = 0x00FF0000U; us_test[i].expected = "16711680"; + i++; us_test[i].num = 0x0000FF00U; us_test[i].expected = "65280"; + i++; us_test[i].num = 0x000000FFU; us_test[i].expected = "255"; + + i++; us_test[i].num = 0xF0000000U; us_test[i].expected = "4026531840"; + i++; us_test[i].num = 0x0F000000U; us_test[i].expected = "251658240"; + i++; us_test[i].num = 0x00F00000U; us_test[i].expected = "15728640"; + i++; us_test[i].num = 0x000F0000U; us_test[i].expected = "983040"; + i++; us_test[i].num = 0x0000F000U; us_test[i].expected = "61440"; + i++; us_test[i].num = 0x00000F00U; us_test[i].expected = "3840"; + i++; us_test[i].num = 0x000000F0U; us_test[i].expected = "240"; + i++; us_test[i].num = 0x0000000FU; us_test[i].expected = "15"; + + i++; us_test[i].num = 0xC0000000U; us_test[i].expected = "3221225472"; + i++; us_test[i].num = 0x0C000000U; us_test[i].expected = "201326592"; + i++; us_test[i].num = 0x00C00000U; us_test[i].expected = "12582912"; + i++; us_test[i].num = 0x000C0000U; us_test[i].expected = "786432"; + i++; us_test[i].num = 0x0000C000U; us_test[i].expected = "49152"; + i++; us_test[i].num = 0x00000C00U; us_test[i].expected = "3072"; + i++; us_test[i].num = 0x000000C0U; us_test[i].expected = "192"; + i++; us_test[i].num = 0x0000000CU; us_test[i].expected = "12"; + + i++; us_test[i].num = 0x00000001U; us_test[i].expected = "1"; + i++; us_test[i].num = 0x00000000U; us_test[i].expected = "0"; + + num_ushort_tests = i; + +#endif + + for(i=1; i<=num_ushort_tests; i++) { + + for(j=0; j