diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-10-19 14:52:19 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-23 14:13:42 +0000 |
commit | 15b5b3b3f01e400e46fe67babe593ede373dac4b (patch) | |
tree | 823f6a27092b9647dbe1f4a9004c99e9975e71c7 /tests/auto/gui/util | |
parent | 726fed0d67013cbfac7921d3d4613ca83406fb0f (diff) |
Add flags to omit/reject padding in scientific notation exponents
The EcmaScript format for printing doubles in exponent form differs
from Qt's format only in this aspect. EcmaScript explicitly prohibits
leading zeroes in exponents. It is thus worthwhile to add those flags
in order to be able to generate and parse doubles in compliance with
EcmaScript.
[ChangeLog][QtCore][QLocale] Additional flags in QLocale::NumberOption
allow generating and parsing doubles in EcmaScript compliant format.
Change-Id: Ia7b82c2e67bb8b80bd890014ff5cd4563faf2a03
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto/gui/util')
-rw-r--r-- | tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp index 78ab769137..f810a92dc5 100644 --- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp +++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp @@ -43,6 +43,8 @@ class tst_QDoubleValidator : public QObject private slots: void validate_data(); void validate(); + void zeroPaddedExponent_data(); + void zeroPaddedExponent(); void validateThouSep_data(); void validateThouSep(); void validateIntEquiv_data(); @@ -240,6 +242,61 @@ void tst_QDoubleValidator::validate() dv.setNotation(QDoubleValidator::StandardNotation); QCOMPARE((int)dv.validate(value, dummy), (int)standard_state); } + +void tst_QDoubleValidator::zeroPaddedExponent_data() +{ + QTest::addColumn<double>("minimum"); + QTest::addColumn<double>("maximum"); + QTest::addColumn<int>("decimals"); + QTest::addColumn<QString>("value"); + QTest::addColumn<bool>("rejectZeroPaddedExponent"); + QTest::addColumn<QValidator::State>("state"); + + QTest::newRow("data01") << 1229.0 << 1231.0 << 0 << QString("123e+1") << false << ACC; + QTest::newRow("data02") << 12290.0 << 12310.0 << 0 << QString("123e2") << false << ACC; + QTest::newRow("data03") << 12.290 << 12.310 << 2 << QString("123e-") << false << ITM; + QTest::newRow("data04") << 12.290 << 12.310 << 2 << QString("123e-1") << false << ACC; + QTest::newRow("data05") << 1.2290 << 1.2310 << 3 << QString("123e-2") << false << ACC; + + QTest::newRow("data11") << 1229.0 << 1231.0 << 0 << QString("123e+1") << true << ACC; + QTest::newRow("data12") << 12290.0 << 12310.0 << 0 << QString("123e2") << true << ACC; + QTest::newRow("data13") << 12.290 << 12.310 << 2 << QString("123e-") << true << ITM; + QTest::newRow("data14") << 12.290 << 12.310 << 2 << QString("123e-1") << true << ACC; + QTest::newRow("data15") << 1.2290 << 1.2310 << 3 << QString("123e-2") << true << ACC; + + QTest::newRow("data21") << 1229.0 << 1231.0 << 0 << QString("123e+01") << false << ACC; + QTest::newRow("data22") << 12290.0 << 12310.0 << 0 << QString("123e02") << false << ACC; + QTest::newRow("data23") << 12.290 << 12.310 << 2 << QString("123e-0") << false << ITM; + QTest::newRow("data24") << 12.290 << 12.310 << 2 << QString("123e-01") << false << ACC; + QTest::newRow("data25") << 1.2290 << 1.2310 << 3 << QString("123e-02") << false << ACC; + + QTest::newRow("data31") << 1229.0 << 1231.0 << 0 << QString("123e+01") << true << INV; + QTest::newRow("data32") << 12290.0 << 12310.0 << 0 << QString("123e02") << true << INV; + QTest::newRow("data33") << 12.290 << 12.310 << 2 << QString("123e-0") << true << INV; + QTest::newRow("data34") << 12.290 << 12.310 << 2 << QString("123e-01") << true << INV; + QTest::newRow("data35") << 1.2290 << 1.2310 << 3 << QString("123e-02") << true << INV; + +} + +void tst_QDoubleValidator::zeroPaddedExponent() +{ + QFETCH(double, minimum); + QFETCH(double, maximum); + QFETCH(int, decimals); + QFETCH(QString, value); + QFETCH(bool, rejectZeroPaddedExponent); + QFETCH(QValidator::State, state); + + QLocale locale(QLocale::C); + if (rejectZeroPaddedExponent) + locale.setNumberOptions(QLocale::RejectLeadingZeroInExponent); + + QDoubleValidator dv(minimum, maximum, decimals, 0); + dv.setLocale(locale); + int dummy; + QCOMPARE((int)dv.validate(value, dummy), (int)state); +} + void tst_QDoubleValidator::notifySignals() { QLocale::setDefault(QLocale("C")); |