/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 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.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. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* * 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 = 0; int failed = 0; 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; for(i = 1; i <= num_ushort_tests; i++) { for(j = 0; j