summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authormakuukka <qt-info@nokia.com>2009-05-29 07:08:27 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-06-10 06:38:13 (GMT)
commitb97671a3b40623c1499c13c3d74c896ac6b9406f (patch)
tree8f68eb88a7449799ad245f484b6c358935c85805 /tests
parentdcaa6ab545e7532b5455734bd8d234cb76b152fa (diff)
downloadQt-b97671a3b40623c1499c13c3d74c896ac6b9406f.zip
Qt-b97671a3b40623c1499c13c3d74c896ac6b9406f.tar.gz
Qt-b97671a3b40623c1499c13c3d74c896ac6b9406f.tar.bz2
Force qRound64() to take a double on platforms where qreal is a float.
In Symbian qreal is defined as float. And in qround64 the parameter was qreal. This qround64 is used (only) in qvariant::convert, when converting from double to e.g. int. This caused overflow bug for some (close to max int) values, because in convert chain double value was casted to float. Task-number: 250267 Reviewed-By: Samuel Rødal Reviewed-By: Jason Barron
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index d15f9c8..9c9ff33 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -255,6 +255,7 @@ private slots:
void convertByteArrayToBool() const;
void convertByteArrayToBool_data() const;
void toIntFromQString() const;
+ void toIntFromDouble() const;
};
Q_DECLARE_METATYPE(QDate)
@@ -2909,5 +2910,30 @@ void tst_QVariant::toIntFromQString() const
QVERIFY(ok);
}
+/*!
+ We verify that:
+ 1. Conversion from (64 bit) double to int works (no overflow).
+ 2. Same conversion works for QVariant::convert.
+
+ Rationale: if 2147483630 is set in float and then converted to int,
+ there will be overflow and the result will be -2147483648.
+
+ See task 250267.
+ */
+void tst_QVariant::toIntFromDouble() const
+{
+ double d = 2147483630; // max int 2147483647
+ QVERIFY((int)d == 2147483630);
+
+ QVariant var(d);
+ QVERIFY( var.canConvert( QVariant::Int ) );
+
+ bool ok;
+ int result = var.toInt(&ok);
+
+ QVERIFY( ok == true );
+ QCOMPARE(result, 2147483630);
+}
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"