/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* * The purpose of this test is to minimally exercise libcurl's internal * curl_m*printf formatting capabilities and handling of some data types. */ #include "test.h" #include #ifdef HAVE_LOCALE_H # include /* for setlocale() */ #endif #include "memdebug.h" #if (SIZEOF_CURL_OFF_T > SIZEOF_LONG) # define MPRNT_SUFFIX_CURL_OFF_T LL #else # define MPRNT_SUFFIX_CURL_OFF_T L #endif #ifdef CURL_ISOCPP # define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val ## Suffix #else # define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val/**/Suffix #endif #define MPRNT_OFF_T_C_HELPER1(Val,Suffix) MPRNT_OFF_T_C_HELPER2(Val,Suffix) #define MPRNT_OFF_T_C(Val) MPRNT_OFF_T_C_HELPER1(Val,MPRNT_SUFFIX_CURL_OFF_T) #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 #define SLONG_TESTS_ARRSZ 1 + 100 #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 */ 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 */ char result[BUFSZ]; /* result string */ }; struct siglong_st { long num; /* signed long */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; struct curloff_st { curl_off_t num; /* curl_off_t */ const char *expected; /* expected string */ char result[BUFSZ]; /* result string */ }; 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