diff options
author | Liang Qi <liang.qi@qt.io> | 2019-02-08 09:28:00 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-02-08 12:31:02 +0100 |
commit | fbfacd33be482fa3cf0aa5cffaf7006d538a2f92 (patch) | |
tree | 92da72786b3740e37004623612c4fc1c9640d30f /src/testlib/qtestcase.cpp | |
parent | c1f4286a5cbc1794fe7be5bdbbd6a0bf29ef84d4 (diff) | |
parent | 74e04d6ace7aa949db97ae2e46c38a4dc0d4d36a (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
src/android/templates/AndroidManifest.xml
src/network/ssl/qsslsocket_mac.cpp
src/widgets/styles/qstylesheetstyle.cpp
tests/auto/corelib/kernel/qtimer/BLACKLIST
tests/auto/testlib/selftests/blacklisted/tst_blacklisted.cpp
tests/auto/testlib/selftests/expected_blacklisted.lightxml
tests/auto/testlib/selftests/expected_blacklisted.tap
tests/auto/testlib/selftests/expected_blacklisted.teamcity
tests/auto/testlib/selftests/expected_blacklisted.txt
tests/auto/testlib/selftests/expected_blacklisted.xml
tests/auto/testlib/selftests/expected_blacklisted.xunitxml
tests/auto/testlib/selftests/expected_float.tap
tests/auto/testlib/selftests/expected_float.teamcity
tests/auto/testlib/selftests/expected_float.txt
tests/auto/testlib/selftests/expected_float.xunitxml
Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Done-With: Edward Welbourne <edward.welbourne@qt.io>
Done-With: Timur Pocheptsov <timur.pocheptsov@qt.io>
Change-Id: If93cc432a56ae3ac1b6533d0028e4dc497415a52
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 4263f9f049..840b4071e2 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2542,7 +2542,7 @@ bool QTest::qCompare(double const &t1, double const &t2, const char *actual, con */ #define TO_STRING_IMPL(TYPE, FORMAT) \ -template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ +template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \ { \ char *msg = new char[128]; \ qsnprintf(msg, 128, #FORMAT, t); \ @@ -2565,8 +2565,57 @@ TO_STRING_IMPL(quint64, %llu) TO_STRING_IMPL(bool, %d) TO_STRING_IMPL(signed char, %hhd) TO_STRING_IMPL(unsigned char, %hhu) -TO_STRING_IMPL(float, %g) -TO_STRING_IMPL(double, %lg) + +/*! + \internal + + Be consistent about leading 0 in exponent. + + POSIX specifies that %e (hence %g when using it) uses at least two digits in + the exponent, requiring a leading 0 on single-digit exponents; (at least) + MinGW includes a leading zero also on an already-two-digit exponent, + e.g. 9e-040, which differs from more usual platforms. So massage that away. + */ +static void massageExponent(char *text) +{ + char *p = strchr(text, 'e'); + if (!p) + return; + const char *const end = p + strlen(p); // *end is '\0' + p += (p[1] == '-' || p[1] == '+') ? 2 : 1; + if (p[0] != '0' || end - 2 <= p) + return; + // We have a leading 0 on an exponent of at least two more digits + const char *n = p + 1; + while (end - 2 > n && n[0] == '0') + ++n; + memmove(p, n, end + 1 - n); +} + +// Be consistent about display of infinities and NaNs (snprintf()'s varies, +// notably on MinGW, despite POSIX documenting "[-]inf" or "[-]infinity" for %f, +// %e and %g, uppercasing for their capital versions; similar for "nan"): +#define TO_STRING_FLOAT(TYPE, FORMAT) \ +template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \ +{ \ + char *msg = new char[128]; \ + switch (std::fpclassify(t)) { \ + case FP_INFINITE: \ + qstrncpy(msg, (t < 0 ? "-inf" : "inf"), 128); \ + break; \ + case FP_NAN: \ + qstrncpy(msg, "nan", 128); \ + break; \ + default: \ + qsnprintf(msg, 128, #FORMAT, t); \ + massageExponent(msg); \ + break; \ + } \ + return msg; \ +} + +TO_STRING_FLOAT(float, %g) +TO_STRING_FLOAT(double, %.12lg) template <> Q_TESTLIB_EXPORT char *QTest::toString<qfloat16>(const qfloat16 &t) { |