/***************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ */ /* * 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" int curl_msprintf(char *buffer, const char *format, ...); #if (CURL_SIZEOF_CURL_OFF_T > 4) # if (CURL_SIZEOF_LONG > 4) # define MPRNT_SUFFIX_CURL_OFF_T L # else # define MPRNT_SUFFIX_CURL_OFF_T LL # endif #else # if (CURL_SIZEOF_LONG > 2) # define MPRNT_SUFFIX_CURL_OFF_T L # else # define MPRNT_SUFFIX_CURL_OFF_T LL # endif #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 NUM_ULONG_TESTS 4 #define NUM_SLONG_TESTS 7 #define NUM_COFFT_TESTS 7 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 unslong_st ul_test[NUM_ULONG_TESTS]; static struct siglong_st sl_test[NUM_SLONG_TESTS]; static struct curloff_st co_test[NUM_COFFT_TESTS]; static int test_unsigned_long_formatting(void) { int i, j; int failed = 0; ul_test[0].num = 0x0L; ul_test[0].expected = "0"; ul_test[1].num = 0x1L; ul_test[1].expected = "1"; #if (CURL_SIZEOF_LONG == 2) ul_test[2].num = 0xFFL; ul_test[2].expected = "255"; ul_test[3].num = 0xFFFFL; ul_test[3].expected = "65535"; #elif (CURL_SIZEOF_LONG == 4) ul_test[2].num = 0xFFFFL; ul_test[2].expected = "65535"; ul_test[3].num = 0xFFFFFFFFL; ul_test[3].expected = "4294967295"; #elif (CURL_SIZEOF_LONG == 8) ul_test[2].num = 0xFFFFFFFFL; ul_test[2].expected = "4294967295"; ul_test[3].num = 0xFFFFFFFFFFFFFFFFL; ul_test[3].expected = "18446744073709551615"; #endif for(i=0; i