summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-07-06 13:52:42 +0200
committerLiang Qi <liang.qi@qt.io>2017-07-06 13:54:25 +0200
commit7f269a5db8b88fbb14ee741f78e726b1a46c7d4d (patch)
treefa63387e6f70187e656dd9e6c4f1cd1b1f96c263 /tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
parent9ca3443a37284bedaf74475c26af173b00757178 (diff)
parent03b4838cb51513bd5d2edf76dccc4bc4a1181681 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: .qmake.conf Change-Id: I43531e087bb810889d5c1fbfcdffb29b78804839
Diffstat (limited to 'tests/auto/corelib/tools/qlocale/tst_qlocale.cpp')
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp67
1 files changed, 61 insertions, 6 deletions
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index a08d600d8c..661074ac16 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -923,6 +923,18 @@ void tst_QLocale::strtod_data()
QTest::addColumn<int>("processed");
QTest::addColumn<bool>("ok");
+ // plain numbers, success
+ QTest::newRow("0") << QString("0") << 0.0 << 1 << true;
+ QTest::newRow("0.") << QString("0.") << 0.0 << 2 << true;
+ QTest::newRow("0.0") << QString("0.0") << 0.0 << 3 << true;
+ QTest::newRow("0e+0") << QString("0e+0") << 0.0 << 4 << true;
+ QTest::newRow("0e-0") << QString("0e-0") << 0.0 << 4 << true;
+ QTest::newRow("0e+1") << QString("0e+1") << 0.0 << 4 << true;
+ QTest::newRow("0e-1") << QString("0e-1") << 0.0 << 4 << true;
+ QTest::newRow("0E+0") << QString("0E+0") << 0.0 << 4 << true;
+ QTest::newRow("0E-0") << QString("0E-0") << 0.0 << 4 << true;
+ QTest::newRow("0E+1") << QString("0E+1") << 0.0 << 4 << true;
+ QTest::newRow("0E-1") << QString("0E-1") << 0.0 << 4 << true;
QTest::newRow("3.4") << QString("3.4") << 3.4 << 3 << true;
QTest::newRow("0.035003945") << QString("0.035003945") << 0.035003945 << 11 << true;
QTest::newRow("3.5003945e-2") << QString("3.5003945e-2") << 0.035003945 << 12 << true;
@@ -931,6 +943,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("12456789012") << QString("12456789012") << 12456789012.0 << 11 << true;
QTest::newRow("1.2456789012e10") << QString("1.2456789012e10") << 12456789012.0 << 15 << true;
+ // starts with junk, fails
+ QTest::newRow("a0") << QString("a0") << 0.0 << 0 << false;
+ QTest::newRow("a0.") << QString("a0.") << 0.0 << 0 << false;
+ QTest::newRow("a0.0") << QString("a0.0") << 0.0 << 0 << false;
QTest::newRow("a3.4") << QString("a3.4") << 0.0 << 0 << false;
QTest::newRow("b0.035003945") << QString("b0.035003945") << 0.0 << 0 << false;
QTest::newRow("c3.5003945e-2") << QString("c3.5003945e-2") << 0.0 << 0 << false;
@@ -939,7 +955,18 @@ void tst_QLocale::strtod_data()
QTest::newRow("f12456789012") << QString("f12456789012") << 0.0 << 0 << false;
QTest::newRow("g1.2456789012e10") << QString("g1.2456789012e10") << 0.0 << 0 << false;
- QTest::newRow("3.4a") << QString("3.4a") << 3.4 << 3 << true;
+ // ends with junk, success
+ QTest::newRow("0a") << QString("0a") << 0.0 << 1 << true;
+ QTest::newRow("0.a") << QString("0.a") << 0.0 << 2 << true;
+ QTest::newRow("0.0a") << QString("0.0a") << 0.0 << 3 << true;
+ QTest::newRow("0e+0a") << QString("0e+0a") << 0.0 << 4 << true;
+ QTest::newRow("0e-0a") << QString("0e-0a") << 0.0 << 4 << true;
+ QTest::newRow("0e+1a") << QString("0e+1a") << 0.0 << 4 << true;
+ QTest::newRow("0e-1a") << QString("0e-1a") << 0.0 << 4 << true;
+ QTest::newRow("0E+0a") << QString("0E+0a") << 0.0 << 4 << true;
+ QTest::newRow("0E-0a") << QString("0E-0a") << 0.0 << 4 << true;
+ QTest::newRow("0E+1a") << QString("0E+1a") << 0.0 << 4 << true;
+ QTest::newRow("0E-1a") << QString("0E-1a") << 0.0 << 4 << true;
QTest::newRow("0.035003945b") << QString("0.035003945b") << 0.035003945 << 11 << true;
QTest::newRow("3.5003945e-2c") << QString("3.5003945e-2c") << 0.035003945 << 12 << true;
QTest::newRow("0.000003945d") << QString("0.000003945d") << 0.000003945 << 11 << true;
@@ -947,6 +974,10 @@ void tst_QLocale::strtod_data()
QTest::newRow("12456789012f") << QString("12456789012f") << 12456789012.0 << 11 << true;
QTest::newRow("1.2456789012e10g") << QString("1.2456789012e10g") << 12456789012.0 << 15 << true;
+ // "0x" prefix, success but only for the "0" before "x"
+ QTest::newRow("0x0") << QString("0x0") << 0.0 << 1 << true;
+ QTest::newRow("0x0.") << QString("0x0.") << 0.0 << 1 << true;
+ QTest::newRow("0x0.0") << QString("0x0.0") << 0.0 << 1 << true;
QTest::newRow("0x3.4") << QString("0x3.4") << 0.0 << 1 << true;
QTest::newRow("0x0.035003945") << QString("0x0.035003945") << 0.0 << 1 << true;
QTest::newRow("0x3.5003945e-2") << QString("0x3.5003945e-2") << 0.0 << 1 << true;
@@ -954,6 +985,9 @@ void tst_QLocale::strtod_data()
QTest::newRow("0x3.945e-6") << QString("0x3.945e-6") << 0.0 << 1 << true;
QTest::newRow("0x12456789012") << QString("0x12456789012") << 0.0 << 1 << true;
QTest::newRow("0x1.2456789012e10") << QString("0x1.2456789012e10") << 0.0 << 1 << true;
+
+ // hexfloat is not supported (yet)
+ QTest::newRow("0x1.921fb5p+1") << QString("0x1.921fb5p+1") << 0.0 << 1 << true;
}
void tst_QLocale::strtod()
@@ -971,6 +1005,28 @@ void tst_QLocale::strtod()
QCOMPARE(result, num);
QCOMPARE(actualOk, ok);
QCOMPARE(static_cast<int>(end - numData.constData()), processed);
+
+ // make sure neither QByteArray, QString or QLocale also work
+ // (but they don't support incomplete parsing)
+ if (processed == num_str.size() || processed == 0) {
+ actualOk = false;
+ QCOMPARE(num_str.toDouble(&actualOk), num);
+ QCOMPARE(actualOk, ok);
+
+ actualOk = false;
+ QCOMPARE(numData.toDouble(&actualOk), num);
+ QCOMPARE(actualOk, ok);
+
+ actualOk = false;
+ QCOMPARE(QLocale::c().toDouble(num_str, &actualOk), num);
+ QCOMPARE(actualOk, ok);
+ }
+
+ // and QStringRef, but we can limit the length without allocating memory
+ QStringRef num_strref(&num_str, 0, processed);
+ actualOk = false;
+ QCOMPARE(QLocale::c().toDouble(num_strref, &actualOk), num);
+ QCOMPARE(actualOk, ok);
}
void tst_QLocale::long_long_conversion_data()
@@ -1593,10 +1649,9 @@ void tst_QLocale::macDefaultLocale()
// make sure we are using the system to parse them
QCOMPARE(locale.toString(1234.56), systemLocaleFormatNumber(QString("1,234.56")));
- QTime currentTime = QTime::currentTime();
- QTime utcTime = QDateTime::currentDateTime().toUTC().time();
-
- int diff = currentTime.hour() - utcTime.hour();
+ QTime testTime = QTime(1, 2, 3);
+ QTime utcTime = QDateTime(QDate::currentDate(), testTime).toUTC().time();
+ int diff = testTime.hour() - utcTime.hour();
// Check if local time and utc time are on opposite sides of the 24-hour wrap-around.
if (diff < -12)
@@ -1604,7 +1659,7 @@ void tst_QLocale::macDefaultLocale()
if (diff > 12)
diff -= 24;
- const QString timeString = locale.toString(QTime(1,2,3), QLocale::LongFormat);
+ const QString timeString = locale.toString(testTime, QLocale::LongFormat);
QVERIFY(timeString.contains(QString("1:02:03")));
// To run this test make sure "Curreny" is US Dollar in System Preferences->Language & Region->Advanced.