From: Martin Baute Date: Wed, 6 Apr 2016 18:33:58 +0000 (+0200) Subject: Tyndur tests X-Git-Url: https://pd.if.org/git/?a=commitdiff_plain;ds=sidebyside;h=689f876fb2420ed2ce45aca58dc39f05e1eb5c2d;hp=5464cb1b36c7db9a0b1720ef79b2a15fd2b1dcdd;p=pdclib Tyndur tests --- diff --git a/functions/_PDCLIB/print.c b/functions/_PDCLIB/print.c index 1c0f5d6..f3df0ec 100644 --- a/functions/_PDCLIB/print.c +++ b/functions/_PDCLIB/print.c @@ -16,24 +16,28 @@ modifiers. */ /* FIXME: one too many flags to work on a 16-bit machine, join some (e.g. the - width flags) into a combined field. */ -#define E_minus 1<<0 -#define E_plus 1<<1 -#define E_alt 1<<2 -#define E_space 1<<3 -#define E_zero 1<<4 -#define E_done 1<<5 -#define E_char 1<<6 -#define E_short 1<<7 -#define E_long 1<<8 -#define E_llong 1<<9 -#define E_intmax 1<<10 -#define E_size 1<<11 -#define E_ptrdiff 1<<12 -#define E_pointer 1<<13 -#define E_ldouble 1<<14 -#define E_lower 1<<15 -#define E_unsigned 1<<16 + width flags) into a combined field. +*/ +#define E_minus (1<<0) +#define E_plus (1<<1) +#define E_alt (1<<2) +#define E_space (1<<3) +#define E_zero (1<<4) +#define E_done (1<<5) + +#define E_char (1<<6) +#define E_short (1<<7) +#define E_long (1<<8) +#define E_llong (1<<9) +#define E_intmax (1<<10) +#define E_size (1<<11) +#define E_ptrdiff (1<<12) +#define E_pointer (1<<13) + +#define E_ldouble (1<<14) + +#define E_lower (1<<15) +#define E_unsigned (1<<16) /* This macro delivers a given character to either a memory buffer or a stream, depending on the contents of 'status' (struct _PDCLIB_status_t). @@ -60,7 +64,7 @@ static void intformat( intmax_t value, struct _PDCLIB_status_t * status ) /* At worst, we need two prefix characters (hex prefix). */ char preface[3] = "\0"; size_t preidx = 0; - if ( ( status->flags & E_alt ) && ( status->base == 16 || status->base == 8 ) ) + if ( ( status->flags & E_alt ) && ( status->base == 16 || status->base == 8 ) && ( value != 0 ) ) { /* Octal / hexadecimal prefix for "%#" conversions */ preface[ preidx++ ] = '0'; diff --git a/functions/stdio/fprintf.c b/functions/stdio/fprintf.c index e95f575..e16adf8 100644 --- a/functions/stdio/fprintf.c +++ b/functions/stdio/fprintf.c @@ -22,12 +22,14 @@ int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCL #endif #ifdef TEST +#include +#include #define _PDCLIB_FILEID "stdio/fprintf.c" #define _PDCLIB_FILEIO #include "_PDCLIB_test.h" -#define testprintf( stream, format, ... ) fprintf( stream, format, __VA_ARGS__ ) +#define testprintf( stream, ... ) fprintf( stream, __VA_ARGS__ ) int main( void ) { diff --git a/functions/stdio/printf.c b/functions/stdio/printf.c index ad1b7f9..6d10113 100644 --- a/functions/stdio/printf.c +++ b/functions/stdio/printf.c @@ -24,10 +24,12 @@ int printf( const char * _PDCLIB_restrict format, ... ) #ifdef TEST #define _PDCLIB_FILEID "stdio/printf.c" #define _PDCLIB_FILEIO +#include +#include #include "_PDCLIB_test.h" -#define testprintf( stream, format, ... ) printf( format, __VA_ARGS__ ) +#define testprintf( stream, ... ) printf( __VA_ARGS__ ) int main( void ) { diff --git a/functions/stdio/snprintf.c b/functions/stdio/snprintf.c index e1a6956..f095b8c 100644 --- a/functions/stdio/snprintf.c +++ b/functions/stdio/snprintf.c @@ -24,10 +24,12 @@ int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict #ifdef TEST #define _PDCLIB_FILEID "stdio/snprintf.c" #define _PDCLIB_STRINGIO +#include +#include #include "_PDCLIB_test.h" -#define testprintf( s, format, ... ) snprintf( s, 100, format, __VA_ARGS__ ) +#define testprintf( s, ... ) snprintf( s, 100, __VA_ARGS__ ) int main( void ) { diff --git a/functions/stdio/sprintf.c b/functions/stdio/sprintf.c index cf686dd..ce3a7ff 100644 --- a/functions/stdio/sprintf.c +++ b/functions/stdio/sprintf.c @@ -25,10 +25,11 @@ int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, .. #ifdef TEST #define _PDCLIB_FILEID "stdio/sprintf.c" #define _PDCLIB_STRINGIO +#include #include "_PDCLIB_test.h" -#define testprintf( s, format, ... ) sprintf( s, format, __VA_ARGS__ ) +#define testprintf( s, ... ) sprintf( s, __VA_ARGS__ ) int main( void ) { diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 0468fa1..9d53d18 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -49,7 +49,7 @@ int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDC #ifdef TEST #define _PDCLIB_FILEID "stdio/vfprintf.c" #define _PDCLIB_FILEIO - +#include #include "_PDCLIB_test.h" static int testprintf( FILE * stream, const char * format, ... ) diff --git a/functions/stdio/vprintf.c b/functions/stdio/vprintf.c index 57e73f3..fe80152 100644 --- a/functions/stdio/vprintf.c +++ b/functions/stdio/vprintf.c @@ -19,7 +19,8 @@ int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) #ifdef TEST #define _PDCLIB_FILEID "stdio/vprintf.c" #define _PDCLIB_FILEIO - +#include +#include #include "_PDCLIB_test.h" static int testprintf( FILE * stream, const char * format, ... ) diff --git a/functions/stdio/vsnprintf.c b/functions/stdio/vsnprintf.c index 3fba970..a46491d 100644 --- a/functions/stdio/vsnprintf.c +++ b/functions/stdio/vsnprintf.c @@ -56,7 +56,8 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric #ifdef TEST #define _PDCLIB_FILEID "stdio/vsnprintf.c" #define _PDCLIB_STRINGIO - +#include +#include #include "_PDCLIB_test.h" static int testprintf( char * s, const char * format, ... ) diff --git a/functions/stdio/vsprintf.c b/functions/stdio/vsprintf.c index 24795a2..4ab2742 100644 --- a/functions/stdio/vsprintf.c +++ b/functions/stdio/vsprintf.c @@ -20,7 +20,8 @@ int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, v #ifdef TEST #define _PDCLIB_FILEID "stdio/vsprintf.c" #define _PDCLIB_STRINGIO - +#include +#include #include "_PDCLIB_test.h" static int testprintf( char * s, const char * format, ... ) diff --git a/testing/_PDCLIB_iotest.h b/testing/_PDCLIB_iotest.h index 7e0e80b..155ac16 100644 --- a/testing/_PDCLIB_iotest.h +++ b/testing/_PDCLIB_iotest.h @@ -13,31 +13,42 @@ /* ...printf() tests */ #if defined( _PDCLIB_FILEIO ) - #define RESULT_MISMATCH( act, exp ) \ - rewind( act ), \ - result_buffer[ fread( result_buffer, 1, strlen( exp ) + 1, act ) ] = '\0', \ - rewind( act ), \ - memcmp( result_buffer, exp, strlen( exp ) ) + #define GET_RESULT \ + rewind( target ); \ + if ( (int)fread( result_buffer, 1, actual_rc, target ) != actual_rc ) \ + { \ + fprintf( stderr, "GET_RESULT failed." ); \ + } + #define RESULT_MISMATCH( act, exp ) strcmp( result_buffer, exp ) != 0 #define RESULT_STRING( tgt ) result_buffer #elif defined( _PDCLIB_STRINGIO ) #define RESULT_MISMATCH( act, exp ) strcmp( act, exp ) != 0 + #define GET_RESULT #define RESULT_STRING( tgt ) tgt #endif #ifdef _PDCLIB_FILEIO -#define PREP_RESULT_BUFFER char result_buffer[100]; +#define PREP_RESULT_BUFFER char result_buffer[100] = { 0 }; rewind( target ); #else #define PREP_RESULT_BUFFER #endif -#define PRINTF_TEST( expected_rc, expected_string, format, ... ) do { \ +#define GETFMT( fmt, ... ) (fmt) +#define PRINTF_TEST( expected_rc, expected_string, ... ) do { \ PREP_RESULT_BUFFER \ - int actual_rc = testprintf( target, format, __VA_ARGS__ ); \ + int actual_rc = testprintf( target, __VA_ARGS__ ); \ + GET_RESULT \ if ( ( actual_rc != expected_rc ) || \ ( RESULT_MISMATCH( target, expected_string ) ) ) \ { \ ++TEST_RESULTS; \ - fprintf( stderr, "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n expected %2d, \"%s\"\n actual %2d, \"%s\"\n", __LINE__, expected_rc, expected_string, actual_rc, RESULT_STRING( target ) ); \ + fprintf( stderr, \ + "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n" \ + " format string \"%s\"\n" \ + " expected %2d, \"%s\"\n" \ + " actual %2d, \"%s\"\n", \ + __LINE__, GETFMT(__VA_ARGS__, 0), expected_rc, \ + expected_string, actual_rc, RESULT_STRING( target ) ); \ } \ } while ( 0 ) @@ -52,10 +63,10 @@ memcpy( source, input_string, sizeof( input_string ) ); #endif -#define SCANF_TEST( expected_rc, input_string, format, ... ) do { \ +#define SCANF_TEST( expected_rc, input_string, ... ) do { \ int actual_rc; \ PREPARE_SOURCE( input_string ); \ - actual_rc = testscanf( source, format, __VA_ARGS__ ); \ + actual_rc = testscanf( source, __VA_ARGS__ ); \ if ( actual_rc != expected_rc ) \ { \ ++TEST_RESULTS; \ diff --git a/testing/_PDCLIB_test.h b/testing/_PDCLIB_test.h index 62f5fb5..b6bc917 100644 --- a/testing/_PDCLIB_test.h +++ b/testing/_PDCLIB_test.h @@ -11,6 +11,7 @@ #include #include #include +#include /* Some strings used for and testing. */ static char const abcde[] = "abcde"; diff --git a/testing/printf_testcases.h b/testing/printf_testcases.h index 6a3d57c..d46e987 100644 --- a/testing/printf_testcases.h +++ b/testing/printf_testcases.h @@ -1,8 +1,19 @@ -{ + { +#if CHAR_MIN == -128 + assert(CHAR_MIN == -128); PRINTF_TEST( 4, "-128", "%hhd", CHAR_MIN ); + assert(CHAR_MAX == 127); PRINTF_TEST( 3, "127", "%hhd", CHAR_MAX ); +#else + assert(CHAR_MIN == 0); + PRINTF_TEST( 1, "0", "%hhd", CHAR_MIN ); + assert(CHAR_MAX == 255); + PRINTF_TEST( 3, "255", "%hhd", CHAR_MAX ); +#endif PRINTF_TEST( 1, "0", "%hhd", 0 ); + assert(SHRT_MIN == -32768); PRINTF_TEST( 6, "-32768", "%hd", SHRT_MIN ); + assert(SHRT_MAX == 32767); PRINTF_TEST( 5, "32767", "%hd", SHRT_MAX ); PRINTF_TEST( 1, "0", "%hd", 0 ); PRINTF_TEST( INT_DIG + 1, "-" INT_MIN_DEZ_STR, "%d", INT_MIN ); @@ -113,4 +124,312 @@ TESTCASE( val2 == 9 ); } #endif -} + } + /* PDCLIB-20: Verify "unusual" combinations of length and signedness */ + PRINTF_TEST( 1, "1", "%tu", (ptrdiff_t) 1); // unsigned prtdiff_t + PRINTF_TEST( 2, "-1", "%jd", (intmax_t) -1); // intmax_t + PRINTF_TEST( 1, "1", "%ju", (uintmax_t) 1); // uintmax_t + PRINTF_TEST( 1, "1", "%zd", (size_t) 1); // signed size_t + +#ifndef TEST_CONVERSION_ONLY +/****************************************************************************** + * NOTE: The following test cases are imported from the Tyndur project. They * + * are therefore under the license of said project, not CC0. * + * As said code comprises test cases, it does not form part of the * + * final compiled library, and has no bearing on its licensing. * + * * + * See bug PDCLIB-6 for full details * + ******************************************************************************/ +/* + * Copyright (c) 2011 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + { + /* Ein String ohne alles */ + PRINTF_TEST(12, "Hallo heimur", "Hallo heimur"); + /* Einfache Konvertierungen */ + PRINTF_TEST(12, "Hallo heimur", "%s", "Hallo heimur"); + PRINTF_TEST(4, "1024", "%d", 1024); + PRINTF_TEST(5, "-1024", "%d", -1024); + PRINTF_TEST(4, "1024", "%i", 1024); + PRINTF_TEST(5, "-1024", "%i", -1024); + PRINTF_TEST(4, "1024", "%u", 1024u); + PRINTF_TEST(10, "4294966272", "%u", -1024u); + PRINTF_TEST(3, "777", "%o", 0777u); + PRINTF_TEST(11, "37777777001", "%o", -0777u); + PRINTF_TEST(8, "1234abcd", "%x", 0x1234abcdu); + PRINTF_TEST(8, "edcb5433", "%x", -0x1234abcdu); + PRINTF_TEST(8, "1234ABCD", "%X", 0x1234abcdu); + PRINTF_TEST(8, "EDCB5433", "%X", -0x1234abcdu); + PRINTF_TEST(1, "x", "%c", 'x'); + PRINTF_TEST(1, "%", "%%"); + /* Mit %c kann man auch Nullbytes ausgeben */ + PRINTF_TEST(1, "\0", "%c", '\0'); + /* Vorzeichen erzwingen (Flag +) */ + PRINTF_TEST(12, "Hallo heimur", "%+s", "Hallo heimur"); + PRINTF_TEST(5, "+1024", "%+d", 1024); + PRINTF_TEST(5, "-1024", "%+d", -1024); + PRINTF_TEST(5, "+1024", "%+i", 1024); + PRINTF_TEST(5, "-1024", "%+i", -1024); + PRINTF_TEST(4, "1024", "%+u", 1024u); + PRINTF_TEST(10, "4294966272", "%+u", -1024u); + PRINTF_TEST(3, "777", "%+o", 0777u); + PRINTF_TEST(11, "37777777001", "%+o", -0777u); + PRINTF_TEST(8, "1234abcd", "%+x", 0x1234abcdu); + PRINTF_TEST(8, "edcb5433", "%+x", -0x1234abcdu); + PRINTF_TEST(8, "1234ABCD", "%+X", 0x1234abcdu); + PRINTF_TEST(8, "EDCB5433", "%+X", -0x1234abcdu); + PRINTF_TEST(1, "x", "%+c", 'x'); + /* Vorzeichenplatzhalter erzwingen (Flag ) */ + PRINTF_TEST(12, "Hallo heimur", "% s", "Hallo heimur"); + PRINTF_TEST(5, " 1024", "% d", 1024); + PRINTF_TEST(5, "-1024", "% d", -1024); + PRINTF_TEST(5, " 1024", "% i", 1024); + PRINTF_TEST(5, "-1024", "% i", -1024); + PRINTF_TEST(4, "1024", "% u", 1024u); + PRINTF_TEST(10, "4294966272", "% u", -1024u); + PRINTF_TEST(3, "777", "% o", 0777u); + PRINTF_TEST(11, "37777777001", "% o", -0777u); + PRINTF_TEST(8, "1234abcd", "% x", 0x1234abcdu); + PRINTF_TEST(8, "edcb5433", "% x", -0x1234abcdu); + PRINTF_TEST(8, "1234ABCD", "% X", 0x1234abcdu); + PRINTF_TEST(8, "EDCB5433", "% X", -0x1234abcdu); + PRINTF_TEST(1, "x", "% c", 'x'); + /* Flag + hat Vorrang über */ + PRINTF_TEST(12, "Hallo heimur", "%+ s", "Hallo heimur"); + PRINTF_TEST(5, "+1024", "%+ d", 1024); + PRINTF_TEST(5, "-1024", "%+ d", -1024); + PRINTF_TEST(5, "+1024", "%+ i", 1024); + PRINTF_TEST(5, "-1024", "%+ i", -1024); + PRINTF_TEST(4, "1024", "%+ u", 1024u); + PRINTF_TEST(10, "4294966272", "%+ u", -1024u); + PRINTF_TEST(3, "777", "%+ o", 0777u); + PRINTF_TEST(11, "37777777001", "%+ o", -0777u); + PRINTF_TEST(8, "1234abcd", "%+ x", 0x1234abcdu); + PRINTF_TEST(8, "edcb5433", "%+ x", -0x1234abcdu); + PRINTF_TEST(8, "1234ABCD", "%+ X", 0x1234abcdu); + PRINTF_TEST(8, "EDCB5433", "%+ X", -0x1234abcdu); + PRINTF_TEST(1, "x", "%+ c", 'x'); + /* Alternative Form */ + PRINTF_TEST(4, "0777", "%#o", 0777u); + PRINTF_TEST(12, "037777777001", "%#o", -0777u); + PRINTF_TEST(10, "0x1234abcd", "%#x", 0x1234abcdu); + PRINTF_TEST(10, "0xedcb5433", "%#x", -0x1234abcdu); + PRINTF_TEST(10, "0X1234ABCD", "%#X", 0x1234abcdu); + PRINTF_TEST(10, "0XEDCB5433", "%#X", -0x1234abcdu); + PRINTF_TEST(1, "0", "%#o", 0u); + PRINTF_TEST(1, "0", "%#x", 0u); + PRINTF_TEST(1, "0", "%#X", 0u); + /* Feldbreite: Kleiner als Ausgabe */ + PRINTF_TEST(12, "Hallo heimur", "%1s", "Hallo heimur"); + PRINTF_TEST(4, "1024", "%1d", 1024); + PRINTF_TEST(5, "-1024", "%1d", -1024); + PRINTF_TEST(4, "1024", "%1i", 1024); + PRINTF_TEST(5, "-1024", "%1i", -1024); + PRINTF_TEST(4, "1024", "%1u", 1024u); + PRINTF_TEST(10, "4294966272", "%1u", -1024u); + PRINTF_TEST(3, "777", "%1o", 0777u); + PRINTF_TEST(11, "37777777001", "%1o", -0777u); + PRINTF_TEST(8, "1234abcd", "%1x", 0x1234abcdu); + PRINTF_TEST(8, "edcb5433", "%1x", -0x1234abcdu); + PRINTF_TEST(8, "1234ABCD", "%1X", 0x1234abcdu); + PRINTF_TEST(8, "EDCB5433", "%1X", -0x1234abcdu); + PRINTF_TEST(1, "x", "%1c", 'x'); + /* Feldbreite: Größer als Ausgabe */ + PRINTF_TEST(20, " Hallo", "%20s", "Hallo"); + PRINTF_TEST(20, " 1024", "%20d", 1024); + PRINTF_TEST(20, " -1024", "%20d", -1024); + PRINTF_TEST(20, " 1024", "%20i", 1024); + PRINTF_TEST(20, " -1024", "%20i", -1024); + PRINTF_TEST(20, " 1024", "%20u", 1024u); + PRINTF_TEST(20, " 4294966272", "%20u", -1024u); + PRINTF_TEST(20, " 777", "%20o", 0777u); + PRINTF_TEST(20, " 37777777001", "%20o", -0777u); + PRINTF_TEST(20, " 1234abcd", "%20x", 0x1234abcdu); + PRINTF_TEST(20, " edcb5433", "%20x", -0x1234abcdu); + PRINTF_TEST(20, " 1234ABCD", "%20X", 0x1234abcdu); + PRINTF_TEST(20, " EDCB5433", "%20X", -0x1234abcdu); + PRINTF_TEST(20, " x", "%20c", 'x'); + /* Feldbreite: Linksbündig */ + PRINTF_TEST(20, "Hallo ", "%-20s", "Hallo"); + PRINTF_TEST(20, "1024 ", "%-20d", 1024); + PRINTF_TEST(20, "-1024 ", "%-20d", -1024); + PRINTF_TEST(20, "1024 ", "%-20i", 1024); + PRINTF_TEST(20, "-1024 ", "%-20i", -1024); + PRINTF_TEST(20, "1024 ", "%-20u", 1024u); + PRINTF_TEST(20, "4294966272 ", "%-20u", -1024u); + PRINTF_TEST(20, "777 ", "%-20o", 0777u); + PRINTF_TEST(20, "37777777001 ", "%-20o", -0777u); + PRINTF_TEST(20, "1234abcd ", "%-20x", 0x1234abcdu); + PRINTF_TEST(20, "edcb5433 ", "%-20x", -0x1234abcdu); + PRINTF_TEST(20, "1234ABCD ", "%-20X", 0x1234abcdu); + PRINTF_TEST(20, "EDCB5433 ", "%-20X", -0x1234abcdu); + PRINTF_TEST(20, "x ", "%-20c", 'x'); + /* Feldbreite: Padding mit 0 */ + PRINTF_TEST(20, "00000000000000001024", "%020d", 1024); + PRINTF_TEST(20, "-0000000000000001024", "%020d", -1024); + PRINTF_TEST(20, "00000000000000001024", "%020i", 1024); + PRINTF_TEST(20, "-0000000000000001024", "%020i", -1024); + PRINTF_TEST(20, "00000000000000001024", "%020u", 1024u); + PRINTF_TEST(20, "00000000004294966272", "%020u", -1024u); + PRINTF_TEST(20, "00000000000000000777", "%020o", 0777u); + PRINTF_TEST(20, "00000000037777777001", "%020o", -0777u); + PRINTF_TEST(20, "0000000000001234abcd", "%020x", 0x1234abcdu); + PRINTF_TEST(20, "000000000000edcb5433", "%020x", -0x1234abcdu); + PRINTF_TEST(20, "0000000000001234ABCD", "%020X", 0x1234abcdu); + PRINTF_TEST(20, "000000000000EDCB5433", "%020X", -0x1234abcdu); + /* Feldbreite: Padding und alternative Form */ + PRINTF_TEST(20, " 0777", "%#20o", 0777u); + PRINTF_TEST(20, " 037777777001", "%#20o", -0777u); + PRINTF_TEST(20, " 0x1234abcd", "%#20x", 0x1234abcdu); + PRINTF_TEST(20, " 0xedcb5433", "%#20x", -0x1234abcdu); + PRINTF_TEST(20, " 0X1234ABCD", "%#20X", 0x1234abcdu); + PRINTF_TEST(20, " 0XEDCB5433", "%#20X", -0x1234abcdu); + PRINTF_TEST(20, "00000000000000000777", "%#020o", 0777u); + PRINTF_TEST(20, "00000000037777777001", "%#020o", -0777u); + PRINTF_TEST(20, "0x00000000001234abcd", "%#020x", 0x1234abcdu); + PRINTF_TEST(20, "0x0000000000edcb5433", "%#020x", -0x1234abcdu); + PRINTF_TEST(20, "0X00000000001234ABCD", "%#020X", 0x1234abcdu); + PRINTF_TEST(20, "0X0000000000EDCB5433", "%#020X", -0x1234abcdu); + /* Feldbreite: - hat Vorrang vor 0 */ + PRINTF_TEST(20, "Hallo ", "%0-20s", "Hallo"); + PRINTF_TEST(20, "1024 ", "%0-20d", 1024); + PRINTF_TEST(20, "-1024 ", "%0-20d", -1024); + PRINTF_TEST(20, "1024 ", "%0-20i", 1024); + PRINTF_TEST(20, "-1024 ", "%0-20i", -1024); + PRINTF_TEST(20, "1024 ", "%0-20u", 1024u); + PRINTF_TEST(20, "4294966272 ", "%0-20u", -1024u); + PRINTF_TEST(20, "777 ", "%-020o", 0777u); + PRINTF_TEST(20, "37777777001 ", "%-020o", -0777u); + PRINTF_TEST(20, "1234abcd ", "%-020x", 0x1234abcdu); + PRINTF_TEST(20, "edcb5433 ", "%-020x", -0x1234abcdu); + PRINTF_TEST(20, "1234ABCD ", "%-020X", 0x1234abcdu); + PRINTF_TEST(20, "EDCB5433 ", "%-020X", -0x1234abcdu); + PRINTF_TEST(20, "x ", "%-020c", 'x'); + /* Feldbreite: Aus Parameter */ + PRINTF_TEST(20, " Hallo", "%*s", 20, "Hallo"); + PRINTF_TEST(20, " 1024", "%*d", 20, 1024); + PRINTF_TEST(20, " -1024", "%*d", 20, -1024); + PRINTF_TEST(20, " 1024", "%*i", 20, 1024); + PRINTF_TEST(20, " -1024", "%*i", 20, -1024); + PRINTF_TEST(20, " 1024", "%*u", 20, 1024u); + PRINTF_TEST(20, " 4294966272", "%*u", 20, -1024u); + PRINTF_TEST(20, " 777", "%*o", 20, 0777u); + PRINTF_TEST(20, " 37777777001", "%*o", 20, -0777u); + PRINTF_TEST(20, " 1234abcd", "%*x", 20, 0x1234abcdu); + PRINTF_TEST(20, " edcb5433", "%*x", 20, -0x1234abcdu); + PRINTF_TEST(20, " 1234ABCD", "%*X", 20, 0x1234abcdu); + PRINTF_TEST(20, " EDCB5433", "%*X", 20, -0x1234abcdu); + PRINTF_TEST(20, " x", "%*c", 20, 'x'); + /* Präzision / Mindestanzahl von Ziffern */ + PRINTF_TEST(12, "Hallo heimur", "%.20s", "Hallo heimur"); + PRINTF_TEST(20, "00000000000000001024", "%.20d", 1024); + PRINTF_TEST(21, "-00000000000000001024", "%.20d", -1024); + PRINTF_TEST(20, "00000000000000001024", "%.20i", 1024); + PRINTF_TEST(21, "-00000000000000001024", "%.20i", -1024); + PRINTF_TEST(20, "00000000000000001024", "%.20u", 1024u); + PRINTF_TEST(20, "00000000004294966272", "%.20u", -1024u); + PRINTF_TEST(20, "00000000000000000777", "%.20o", 0777u); + PRINTF_TEST(20, "00000000037777777001", "%.20o", -0777u); + PRINTF_TEST(20, "0000000000001234abcd", "%.20x", 0x1234abcdu); + PRINTF_TEST(20, "000000000000edcb5433", "%.20x", -0x1234abcdu); + PRINTF_TEST(20, "0000000000001234ABCD", "%.20X", 0x1234abcdu); + PRINTF_TEST(20, "000000000000EDCB5433", "%.20X", -0x1234abcdu); + /* Feldbreite und Präzision */ + PRINTF_TEST(20, " Hallo", "%20.5s", "Hallo heimur"); + PRINTF_TEST(20, " 01024", "%20.5d", 1024); + PRINTF_TEST(20, " -01024", "%20.5d", -1024); + PRINTF_TEST(20, " 01024", "%20.5i", 1024); + PRINTF_TEST(20, " -01024", "%20.5i", -1024); + PRINTF_TEST(20, " 01024", "%20.5u", 1024u); + PRINTF_TEST(20, " 4294966272", "%20.5u", -1024u); + PRINTF_TEST(20, " 00777", "%20.5o", 0777u); + PRINTF_TEST(20, " 37777777001", "%20.5o", -0777u); + PRINTF_TEST(20, " 1234abcd", "%20.5x", 0x1234abcdu); + PRINTF_TEST(20, " 00edcb5433", "%20.10x", -0x1234abcdu); + PRINTF_TEST(20, " 1234ABCD", "%20.5X", 0x1234abcdu); + PRINTF_TEST(20, " 00EDCB5433", "%20.10X", -0x1234abcdu); + /* Präzision: 0 wird ignoriert */ + PRINTF_TEST(20, " Hallo", "%020.5s", "Hallo heimur"); + PRINTF_TEST(20, " 01024", "%020.5d", 1024); + PRINTF_TEST(20, " -01024", "%020.5d", -1024); + PRINTF_TEST(20, " 01024", "%020.5i", 1024); + PRINTF_TEST(20, " -01024", "%020.5i", -1024); + PRINTF_TEST(20, " 01024", "%020.5u", 1024u); + PRINTF_TEST(20, " 4294966272", "%020.5u", -1024u); + PRINTF_TEST(20, " 00777", "%020.5o", 0777u); + PRINTF_TEST(20, " 37777777001", "%020.5o", -0777u); + PRINTF_TEST(20, " 1234abcd", "%020.5x", 0x1234abcdu); + PRINTF_TEST(20, " 00edcb5433", "%020.10x", -0x1234abcdu); + PRINTF_TEST(20, " 1234ABCD", "%020.5X", 0x1234abcdu); + PRINTF_TEST(20, " 00EDCB5433", "%020.10X", -0x1234abcdu); + /* Präzision 0 */ + PRINTF_TEST(0, "", "%.0s", "Hallo heimur"); + PRINTF_TEST(20, " ", "%20.0s", "Hallo heimur"); + PRINTF_TEST(0, "", "%.s", "Hallo heimur"); + PRINTF_TEST(20, " ", "%20.s", "Hallo heimur"); + PRINTF_TEST(20, " 1024", "%20.0d", 1024); + PRINTF_TEST(20, " -1024", "%20.d", -1024); + PRINTF_TEST(20, " ", "%20.d", 0); + PRINTF_TEST(20, " 1024", "%20.0i", 1024); + PRINTF_TEST(20, " -1024", "%20.i", -1024); + PRINTF_TEST(20, " ", "%20.i", 0); + PRINTF_TEST(20, " 1024", "%20.u", 1024u); + PRINTF_TEST(20, " 4294966272", "%20.0u", -1024u); + PRINTF_TEST(20, " ", "%20.u", 0u); + PRINTF_TEST(20, " 777", "%20.o", 0777u); + PRINTF_TEST(20, " 37777777001", "%20.0o", -0777u); + PRINTF_TEST(20, " ", "%20.o", 0u); + PRINTF_TEST(20, " 1234abcd", "%20.x", 0x1234abcdu); + PRINTF_TEST(20, " edcb5433", "%20.0x", -0x1234abcdu); + PRINTF_TEST(20, " ", "%20.x", 0u); + PRINTF_TEST(20, " 1234ABCD", "%20.X", 0x1234abcdu); + PRINTF_TEST(20, " EDCB5433", "%20.0X", -0x1234abcdu); + PRINTF_TEST(20, " ", "%20.X", 0u); + /* Negative Präzision wird ignoriert */ + /* XXX glibc tut nicht, was ich erwartet habe, vorerst deaktiviert... */ + /* + * Präzision und Feldbreite aus Parameter. + * + hat Vorrang vor , - hat Vorrang vor 0 (das eh ignoriert wird, + * weil eine Präzision angegeben ist) + */ + PRINTF_TEST(20, "Hallo ", "% -0+*.*s", 20, 5, "Hallo heimur"); + PRINTF_TEST(20, "+01024 ", "% -0+*.*d", 20, 5, 1024); + PRINTF_TEST(20, "-01024 ", "% -0+*.*d", 20, 5, -1024); + PRINTF_TEST(20, "+01024 ", "% -0+*.*i", 20, 5, 1024); + PRINTF_TEST(20, "-01024 ", "% 0-+*.*i", 20, 5, -1024); + PRINTF_TEST(20, "01024 ", "% 0-+*.*u", 20, 5, 1024u); + PRINTF_TEST(20, "4294966272 ", "% 0-+*.*u", 20, 5, -1024u); + PRINTF_TEST(20, "00777 ", "%+ -0*.*o", 20, 5, 0777u); + PRINTF_TEST(20, "37777777001 ", "%+ -0*.*o", 20, 5, -0777u); + PRINTF_TEST(20, "1234abcd ", "%+ -0*.*x", 20, 5, 0x1234abcdu); + PRINTF_TEST(20, "00edcb5433 ", "%+ -0*.*x", 20, 10, -0x1234abcdu); + PRINTF_TEST(20, "1234ABCD ", "% -+0*.*X", 20, 5, 0x1234abcdu); + PRINTF_TEST(20, "00EDCB5433 ", "% -+0*.*X", 20, 10, -0x1234abcdu); + } +/******************************************************************************/ +#endif +