/* PDCLib testing suite <_PDCLIB_test.h>

   This file is part of the Public Domain C Library (PDCLib).
   Permission is granted to use, modify, and / or redistribute at will.
*/

/* -------------------------------------------------------------------------- */
/* Helper macros for printf() / scanf() tests                                 */
/* -------------------------------------------------------------------------- */
/* Tucked away in a seperate header because these are ugly, complex, and not  */
/* needed in 95% of all test cases.                                           */
/* -------------------------------------------------------------------------- */
/* ...scanf() tests */
#if defined( _PDCLIB_FILEIO )
    #define PREPARE_SOURCE( input_string ) \
        rewind( source ); \
        fwrite( input_string, 1, sizeof( input_string ), source ); \
        rewind( source );
#elif defined( _PDCLIB_STRINGIO )
    #define PREPARE_SOURCE( input_string ) \
        memcpy( source, input_string, sizeof( input_string ) );
#endif

/* Virtually everything in the printf() / scanf() test drivers is heavily
   depending on the platform, i.e. the width of the integer values. To do
   proper domain tests, we need the limits of the integers (largest and
   smallest value), which we can get from <limits.h>. But we also need the
   string representations of these numbers, to the various bases, which of
   course vary depending on how the platform defines 'int' and 'long'.
*/

#define sym2v( x ) #x
#define sym2s( x ) sym2v( x )

#if __SIZEOF_INT__ == 2

#define UINT_DIG 5
#define INT_DIG  5
#define INT_DIG_LESS1 "4"
#define INT_DIG_PLUS1 "6"
#define INT_DIG_PLUS2 "7"
#define INT_HEXDIG "FFF"
#define INT_hexdig "fff"
#define INT_OCTDIG "177777"
#define INT_MAX_DEZ_STR  "32767"
#define INT_MIN_DEZ_STR  "32768"
#define UINT_MAX_DEZ_STR "65535"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR

#elif __SIZEOF_INT__ == 4

#define UINT_DIG 10
#define INT_DIG  10
#define INT_DIG_LESS1 "9"
#define INT_DIG_PLUS1 "11"
#define INT_DIG_PLUS2 "12"
#define INT_HEXDIG "FFFFFFF"
#define INT_hexdig "fffffff"
#define INT_OCTDIG "37777777777"
#define INT_MAX_DEZ_STR  "2147483647"
#define INT_MIN_DEZ_STR  "2147483648"
#define UINT_MAX_DEZ_STR "4294967295"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR

#elif __SIZEOF_INT__ == 8

#define UINT_DIG 20
#define INT_DIG  19
#define INT_DIG_LESS1 "18"
#define INT_DIG_PLUS1 "20"
#define INT_DIG_PLUS2 "21"
#define INT_HEXDIG "FFFFFFFFFFFFFFF"
#define INT_hexdig "fffffffffffffff"
#define INT_OCTDIG "1777777777777777777777"
#define INT_MAX_DEZ_STR   "9223372036854775807"
#define INT_MIN_DEZ_STR   "9223372036854775808"
#define UINT_MAX_DEZ_STR "18446744073709551615"
#define INT_MAX_OCT_STR
#define INT_MIN_OCT_STR
#define UINT_MAX_OCT_STR
#define INT_MAX_HEX_STR
#define INT_MIN_HEX_STR
#define UINT_MAX_HEX_STR

#else

#error Unsupported width of 'int' (neither 16, 32, nor 64 bit).

#endif


#if __SIZEOF_LONG__ == 4

#define ULONG_DIG 10
#define LONG_DIG  10
#define LONG_MAX_DEZ_STR  "2147483647"
#define LONG_MIN_DEZ_STR  "2147483648"
#define ULONG_MAX_DEZ_STR "4294967295"
#define LONG_MAX_OCT_STR
#define LONG_MIN_OCT_STR
#define ULONG_MAX_OCT_STR
#define LONG_MAX_HEX_STR
#define LONG_MIN_HEX_STR
#define ULONG_MAX_HEX_STR

#elif __SIZEOF_LONG__ == 8

#define ULONG_DIG 20
#define LONG_DIG  19
#define LONG_MAX_DEZ_STR   "9223372036854775807"
#define LONG_MIN_DEZ_STR   "9223372036854775808"
#define ULONG_MAX_DEZ_STR "18446744073709551615"
#define LONG_MAX_OCT_STR
#define LONG_MIN_OCT_STR
#define ULONG_MAX_OCT_STR
#define LONG_MAX_HEX_STR
#define LONG_MIN_HEX_STR
#define ULONG_MAX_HEX_STR

#else

#error Unsupported width of 'long' (neither 32 nor 64 bit).

#endif


#if __SIZEOF_LONG_LONG__ == 8

#define ULLONG_DIG 20
#define LLONG_DIG  19
#define LLONG_MAX_DEZ_STR   "9223372036854775807"
#define LLONG_MIN_DEZ_STR   "9223372036854775808"
#define ULLONG_MAX_DEZ_STR "18446744073709551615"
#define LLONG_MAX_OCT_STR
#define LLONG_MIN_OCT_STR
#define ULLONG_MAX_OCT_STR
#define LLONG_MAX_HEX_STR
#define LLONG_MIN_HEX_STR
#define ULLONG_MAX_HEX_STR

#elif __SIZEOF_LONG_LONG__ == 16

#define ULLONG_DIG 38
#define LLONG_DIG  38
#define LLONG_MAX_DEZ_STR  "170141183460469231731687303715884105727"
#define LLONG_MIN_DEZ_STR  "170141183460469231731687303715884105728"
#define ULLONG_MAX_DEZ_STR "340282366920938463463374607431768211455"
#define LLONG_MAX_OCT_STR
#define LLONG_MIN_OCT_STR
#define ULLONG_MAX_OCT_STR
#define LLONG_MAX_HEX_STR
#define LLONG_MIN_HEX_STR
#define ULLONG_MAX_HEX_STR

#else

#error Unsupported width of 'long long' (neither 64 nor 128 bit).

#endif
