summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-05-30 16:56:20 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-05 06:14:57 +0200
commit872f0b94ac7a863c59bf1175b94cca3b3636cf13 (patch)
tree41951b0fd58977349f6a621c487de0cd0bbb6a8c /tests
parent93ead3593997f9b67868170aa0f876eec30d3130 (diff)
Make QString("inf").toFloat() return inf instead of zero.
Currently, QString::toFloat() returns 0 (and sets ok to false) if you try to convert "inf". This is because inf is greater than QT_MAX_FLOAT and there is currently no check to handle inf. Task-number: QTBUG-8629 Change-Id: I498daf4a7a6f880f928461fca628fcaf7d1d6d08 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index a3c418c1bb..8d96861eb9 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -4850,6 +4850,21 @@ void tst_QString::nanAndInf()
QString("0INF0").toLong(&ok, 36);
QVERIFY(ok);
+
+ // Check that inf (float) => "inf" (QString) => inf (float).
+ float value = qInf();
+ QString valueAsString = QString::number(value);
+ QCOMPARE(valueAsString, QString::fromLatin1("inf"));
+ float valueFromString = valueAsString.toFloat();
+ QVERIFY(qIsInf(valueFromString));
+
+ // Check that -inf (float) => "-inf" (QString) => -inf (float).
+ value = -qInf();
+ valueAsString = QString::number(value);
+ QCOMPARE(valueAsString, QString::fromLatin1("-inf"));
+ valueFromString = valueAsString.toFloat();
+ QVERIFY(value == -qInf());
+ QVERIFY(qIsInf(valueFromString));
}
void tst_QString::arg_fillChar_data()