summaryrefslogtreecommitdiffstats
path: root/tests/auto/qvariant
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-12-08 11:15:19 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-12-09 08:59:41 (GMT)
commitd5d39f04c2c473401e9147d57d5a7c62f6111656 (patch)
treee622a118ee8bad5561d913b84af4be591d37187d /tests/auto/qvariant
parent5a700d89a2263bcfc91d785c1ed444b1ecdacf83 (diff)
downloadQt-d5d39f04c2c473401e9147d57d5a7c62f6111656.zip
Qt-d5d39f04c2c473401e9147d57d5a7c62f6111656.tar.gz
Qt-d5d39f04c2c473401e9147d57d5a7c62f6111656.tar.bz2
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 3d68a73..ae0131c 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"