Fix printf tests for recent MinGW versions
The default mantissa length was changed from 3 to 2 in MinGW 5.0.4. Fix the test for printing pointer addresses in 64bit MinGW.
This commit is contained in:
parent
f3ae302b4d
commit
bcfc9a8a26
@ -849,9 +849,7 @@ void StringTestCase::FromDouble()
|
|||||||
} testData[] =
|
} testData[] =
|
||||||
{
|
{
|
||||||
{ 1.23, -1, "1.23" },
|
{ 1.23, -1, "1.23" },
|
||||||
// All MSVC versions until MSVC 14 used 3 digits for the exponent
|
#if defined(wxDEFAULT_MANTISSA_SIZE_3)
|
||||||
// unnecessarily, account for this non-standard behaviour.
|
|
||||||
#if defined(wxUSING_VC_CRT_IO) && !wxCHECK_VISUALC_VERSION(14)
|
|
||||||
{ -3e-10, -1, "-3e-010" },
|
{ -3e-10, -1, "-3e-010" },
|
||||||
#else
|
#else
|
||||||
{ -3e-10, -1, "-3e-10" },
|
{ -3e-10, -1, "-3e-10" },
|
||||||
|
@ -71,12 +71,6 @@ int r;
|
|||||||
CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
|
CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
|
||||||
ASSERT_STR_EQUAL( wxT(expected), buf );
|
ASSERT_STR_EQUAL( wxT(expected), buf );
|
||||||
|
|
||||||
#define CMP3i(expected, fmt, y) \
|
|
||||||
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y); \
|
|
||||||
CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
|
|
||||||
WX_ASSERT_MESSAGE( ("Expected \"%s\", got \"%s\"", expected, buf), \
|
|
||||||
wxStricmp(expected, buf) == 0 );
|
|
||||||
|
|
||||||
#define CMP2(expected, fmt) \
|
#define CMP2(expected, fmt) \
|
||||||
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt)); \
|
r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt)); \
|
||||||
CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
|
CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
|
||||||
@ -241,22 +235,23 @@ void VsnprintfTestCase::P()
|
|||||||
// the system sprintf() for actual formatting so the results are still
|
// the system sprintf() for actual formatting so the results are still
|
||||||
// different under different systems).
|
// different under different systems).
|
||||||
|
|
||||||
#ifdef wxUSING_VC_CRT_IO
|
#if defined(__VISUALC__) || (defined(__MINGW32__) && \
|
||||||
// MSVC always prints pointers as %8X on 32 bit systems and as %16X on 64
|
(!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO))
|
||||||
// bit systems.
|
|
||||||
#if SIZEOF_VOID_P == 4
|
#if SIZEOF_VOID_P == 4
|
||||||
CMP3i("00ABCDEF", "%p", (void*)0xABCDEF);
|
CMP3("00ABCDEF", "%p", (void*)0xABCDEF);
|
||||||
CMP3("00000000", "%p", (void*)NULL);
|
CMP3("00000000", "%p", (void*)NULL);
|
||||||
#elif SIZEOF_VOID_P == 8
|
#elif SIZEOF_VOID_P == 8
|
||||||
CMP3i("0000ABCDEFABCDEF", "%p", (void*)0xABCDEFABCDEF);
|
CMP3("0000ABCDEFABCDEF", "%p", (void*)0xABCDEFABCDEF);
|
||||||
CMP3("0000000000000000", "%p", (void*)NULL);
|
CMP3("0000000000000000", "%p", (void*)NULL);
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__MINGW32__)
|
#elif defined(__MINGW32__)
|
||||||
// mingw32 uses MSVC CRT in old versions but is own implementation now
|
#if SIZEOF_VOID_P == 4
|
||||||
// which is somewhere in the middle as it uses %8x, so to catch both cases
|
CMP3("00abcdef", "%p", (void*)0xABCDEF);
|
||||||
// we use case-insensitive comparison here.
|
CMP3("00000000", "%p", (void*)NULL);
|
||||||
CMP3("0xabcdef", "%p", (void*)0xABCDEF);
|
#elif SIZEOF_VOID_P == 8
|
||||||
CMP3("0", "%p", (void*)NULL);
|
CMP3("0000abcdefabcdef", "%p", (void*)0xABCDEFABCDEF);
|
||||||
|
CMP3("0000000000000000", "%p", (void*)NULL);
|
||||||
|
#endif
|
||||||
#elif defined(__GNUG__)
|
#elif defined(__GNUG__)
|
||||||
// glibc prints pointers as %#x except for NULL pointers which are printed
|
// glibc prints pointers as %#x except for NULL pointers which are printed
|
||||||
// as '(nil)'.
|
// as '(nil)'.
|
||||||
@ -275,13 +270,10 @@ void VsnprintfTestCase::N()
|
|||||||
|
|
||||||
void VsnprintfTestCase::E()
|
void VsnprintfTestCase::E()
|
||||||
{
|
{
|
||||||
// NB: there are no standards about the minimum exponent width
|
// NB: Use at least three digits for the exponent to workaround
|
||||||
// (and the width of the %e conversion specifier refers to the
|
// differences between MSVC, MinGW and GNU libc.
|
||||||
// mantissa, not to the exponent).
|
// See wxUSING_MANTISSA_SIZE_3 in testprec.h as well.
|
||||||
// Since newer MSVC versions use 3 digits as minimum exponent
|
//
|
||||||
// width while GNU libc uses 2 digits as minimum width, here we
|
|
||||||
// workaround this problem using for the exponent values with at
|
|
||||||
// least three digits.
|
|
||||||
// Some examples:
|
// Some examples:
|
||||||
// printf("%e",2.342E+02);
|
// printf("%e",2.342E+02);
|
||||||
// -> under MSVC7.1 prints: 2.342000e+002
|
// -> under MSVC7.1 prints: 2.342000e+002
|
||||||
@ -601,8 +593,7 @@ void VsnprintfTestCase::GlibcMisc1()
|
|||||||
{
|
{
|
||||||
CMP3(" ", "%5.s", "xyz");
|
CMP3(" ", "%5.s", "xyz");
|
||||||
CMP3(" 33", "%5.f", 33.3);
|
CMP3(" 33", "%5.f", 33.3);
|
||||||
#ifdef wxUSING_VC_CRT_IO
|
#if defined(wxDEFAULT_MANTISSA_SIZE_3)
|
||||||
// see the previous notes about the minimum width of mantissa:
|
|
||||||
CMP3(" 3e+008", "%8.e", 33.3e7);
|
CMP3(" 3e+008", "%8.e", 33.3e7);
|
||||||
CMP3(" 3E+008", "%8.E", 33.3e7);
|
CMP3(" 3E+008", "%8.E", 33.3e7);
|
||||||
CMP3("3e+001", "%.g", 33.3);
|
CMP3("3e+001", "%.g", 33.3);
|
||||||
|
@ -36,21 +36,24 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define wxUSING_VC_CRT_IO when using MSVC CRT STDIO library as its standard
|
// Define wxUSING_MANTISSA_SIZE_3 for certain versions of MinGW and MSVC.
|
||||||
// functions give different results from glibc ones in several cases (of
|
// These use a CRT which prints the exponent with a minimum of 3
|
||||||
// course, any code relying on this is not portable and probably won't work,
|
// digits instead of 2.
|
||||||
// i.e. will result in tests failures, with other platforms/compilers which
|
|
||||||
// should have checks for them added as well).
|
|
||||||
//
|
//
|
||||||
// Notice that MinGW uses VC CRT by default but may use its own printf()
|
// This happens for all MSVC compilers before version 14 (VS2015).
|
||||||
// implementation if __USE_MINGW_ANSI_STDIO is defined. And finally also notice
|
// And for MinGW when it does not define or set __USE_MINGW_ANSI_STDIO.
|
||||||
// that testing for __USE_MINGW_ANSI_STDIO directly results in a warning with
|
// Since MinGW 5.0.4 it uses at least 2 digits for the exponent:
|
||||||
// -Wundef if it involves an operation with undefined __MINGW_FEATURES__ so
|
// https://sourceforge.net/p/mingw-w64/mailman/message/36333746/
|
||||||
// test for the latter too to avoid it.
|
|
||||||
#if defined(__VISUALC__) || \
|
#if (defined(__MINGW64_VERSION_MAJOR) && (__MINGW64_VERSION_MAJOR > 5 || \
|
||||||
(defined(__MINGW32__) && \
|
(__MINGW64_VERSION_MAJOR == 5 && __MINGW64_VERSION_MINOR >= 0) || \
|
||||||
(!defined(__MINGW_FEATURES__) || !__USE_MINGW_ANSI_STDIO))
|
(__MINGW64_VERSION_MAJOR == 5 && __MINGW64_VERSION_MINOR == 0 && __MINGW64_VERSION_BUGFIX >= 4)))
|
||||||
#define wxUSING_VC_CRT_IO
|
#define wxMINGW_WITH_FIXED_MANTISSA
|
||||||
|
#endif
|
||||||
|
#if (defined(__VISUALC__) && !wxCHECK_VISUALC_VERSION(14)) || \
|
||||||
|
(defined(__MINGW32__) && !defined(wxMINGW_WITH_FIXED_MANTISSA) && \
|
||||||
|
(!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO))
|
||||||
|
#define wxDEFAULT_MANTISSA_SIZE_3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// thrown when assert fails in debug build
|
// thrown when assert fails in debug build
|
||||||
|
Loading…
Reference in New Issue
Block a user