diff options
Diffstat (limited to 'tests/auto/qvariant')
-rw-r--r-- | tests/auto/qvariant/qvariant.pro | 1 | ||||
-rw-r--r-- | tests/auto/qvariant/tst_qvariant.cpp | 28 |
2 files changed, 27 insertions, 2 deletions
diff --git a/tests/auto/qvariant/qvariant.pro b/tests/auto/qvariant/qvariant.pro index 747b6c3..2c9c8d7 100644 --- a/tests/auto/qvariant/qvariant.pro +++ b/tests/auto/qvariant/qvariant.pro @@ -1,6 +1,5 @@ load(qttest_p4) SOURCES += tst_qvariant.cpp - QT += network contains(QT_CONFIG, qt3support): QT += qt3support diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 9ad4482..6059364 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -266,6 +266,7 @@ private slots: void convertByteArrayToBool() const; void convertByteArrayToBool_data() const; void toIntFromQString() const; + void toIntFromDouble() const; void task256984_setValue(); }; @@ -3050,6 +3051,31 @@ 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); +} + void tst_QVariant::task256984_setValue() { QTransform t; //we just take a value so that we're sure that it will be shared @@ -3060,7 +3086,7 @@ void tst_QVariant::task256984_setValue() QVERIFY( !v2.isDetached() ); qVariantSetValue(v2, 3); //set an integer value - + QVERIFY( v1.isDetached() ); QVERIFY( v2.isDetached() ); } |