summaryrefslogtreecommitdiff
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.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 9ad4482b8c..60593646c2 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() );
}