summaryrefslogtreecommitdiffstats
path: root/tests/auto/qvariant
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-12-08 12:15:19 +0100
committerOlivier Goffart <ogoffart@trolltech.com>2009-12-09 09:59:41 +0100
commitd5d39f04c2c473401e9147d57d5a7c62f6111656 (patch)
treee622a118ee8bad5561d913b84af4be591d37187d /tests/auto/qvariant
parent5a700d89a2263bcfc91d785c1ed444b1ecdacf83 (diff)
Fix regression in qVariantFromValue when converting from complex type to simple type
QVariant v = QColor(Qt::red); v.setValue(1000); Would produce a variant with garbage. the destructor of QColor would not be called, and the 1000 would be in the QVariant::PrivateShared, while most of the QVariant code assume that numbers are dirrectly in the QVariant::Data union Task-number: QTBUG-6602 Reviewed-by: Thierry
Diffstat (limited to 'tests/auto/qvariant')
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 3d68a734db..ae0131c07e 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -272,6 +272,8 @@ private slots:
void numericalConvert();
void moreCustomTypes();
void variantInVariant();
+
+ void colorInteger();
};
Q_DECLARE_METATYPE(QDate)
@@ -3388,5 +3390,20 @@ void tst_QVariant::variantInVariant()
QCOMPARE(qvariant_cast<QVariant>(var9), var1);
}
+void tst_QVariant::colorInteger()
+{
+ QVariant v = QColor(Qt::red);
+ QCOMPARE(v.type(), QVariant::Color);
+ QCOMPARE(v.value<QColor>(), QColor(Qt::red));
+
+ v.setValue(1000);
+ QCOMPARE(v.type(), QVariant::Int);
+ QCOMPARE(v.toInt(), 1000);
+
+ v.setValue(QColor(Qt::yellow));
+ QCOMPARE(v.type(), QVariant::Color);
+ QCOMPARE(v.value<QColor>(), QColor(Qt::yellow));
+}
+
QTEST_MAIN(tst_QVariant)
#include "tst_qvariant.moc"