summaryrefslogtreecommitdiffstats
path: root/tests/auto/qvariant/tst_qvariant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qvariant/tst_qvariant.cpp')
-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"