From fdbddb179ba32d170f384fbaac224725a68be4a2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 9 May 2023 13:11:01 +0200 Subject: [PATCH] Test QLocale's parsing of small fractions with big exponents Add some tests inspired by the initial form of a bug report (before we found out what the real issue was), that a small fraction with a large exponent is correctly handled. This should work as long as the result is representable, even if the fraction itself is too small to be represented by the floating-point type. Task-number: QTBUG-113443 Change-Id: Ie004197961fc7b603e5024a6ebc5928261a0e2bb Reviewed-by: Ievgenii Meshcheriakov Reviewed-by: Qt CI Bot (cherry picked from commit 74b377313e98e0fa745e21524e220c9619dd8bb2) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index e7ab92f2ee0..a5b5e983b8d 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -903,6 +903,13 @@ void tst_QLocale::stringToDouble_data() // Underflow: QTest::newRow("C tiny") << QString("C") << QString("2e-324") << false << 0.; QTest::newRow("C -tiny") << QString("C") << QString("-2e-324") << false << 0.; + + // Test a tiny fraction (well beyond denomal) with a huge exponent: + const QString zeros(500, '0'); + QTest::newRow("C tiny fraction, huge exponent") + << u"C"_s << u"0."_s + zeros + u"123e501"_s << true << 1.23; + QTest::newRow("uk_UA tiny fraction, huge exponent") + << u"uk_UA"_s << u"0,"_s + zeros + u"123\u0415" "501"_s << true << 1.23; } void tst_QLocale::stringToDouble() @@ -990,6 +997,13 @@ void tst_QLocale::stringToFloat_data() // Underflow double, too: QTest::newRow("C tiny") << C << QString("2e-324") << false << 0.; QTest::newRow("C -tiny") << C << QString("-2e-324") << false << 0.; + + // Test a small fraction (well beyond denomal) with a big exponent: + const QString zeros(80, '0'); + QTest::newRow("C small fraction, big exponent") + << u"C"_s << u"0."_s + zeros + u"123e81"_s << true << 1.23; + QTest::newRow("uk_UA small fraction, big exponent") + << u"uk_UA"_s << u"0,"_s + zeros + u"123\u0415" "81"_s << true << 1.23; } void tst_QLocale::stringToFloat()