diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2011-10-12 17:32:26 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-09 10:11:34 +0100 |
commit | 8fd64d22ac7892b061a09c42c72aacf033b80876 (patch) | |
tree | 9c0d04049188ad5ff726419279ee88c3fdd0d1bf /tests/auto/corelib/kernel | |
parent | 2b39be6dd5d111482e5df06ac6dea18ca338d9f0 (diff) |
Make usage of internal QVariant space.
Each QVariant instance has internal storage which may be
used for well-know basic types. This patch changes the
behavior by delegating type dependent operation to QMetaType
class which knows more types than QVariant itself.
The patch significantly reduce amount of code in QVariant
implementation.
There are few side effects of this patch:
- better performance:
* for Core types when using Gui (QGuiVariant is able to
construct Core types)
* for small custom types (QVariant::Private::Data is used for all
types that has size small enough)
- comparing two QVariants can give different result for small custom
types (binary comparison instead of pointer comparison)
Change-Id: Ic17fa500d6a882110bfba896fd456c8e6c7a63a9
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index c4fed9088f..21bdfa7791 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -325,6 +325,10 @@ void tst_QVariant::isNull() QVariant var; QVERIFY( var.isNull() ); + QString str1; + QVariant var1( str1 ); + QVERIFY( var1.isNull() ); + QVariant var2( QString::null ); QVERIFY( var2.isNull() ); @@ -2017,10 +2021,12 @@ void tst_QVariant::userType() QVariant userVar3; qVariantSetValue(userVar3, data2); - QVERIFY(userVar2 != userVar3); + QVERIFY(userVar2 == userVar3); userVar3 = userVar2; QVERIFY(userVar2 == userVar3); } + // At this point all QVariants got destroyed but we have 2 MyType instances. + QCOMPARE(instanceCount, 2); { QVariant userVar; qVariantSetValue(userVar, &data); @@ -2056,10 +2062,9 @@ void tst_QVariant::userType() QVariant myCarrier; qVariantSetValue(myCarrier, data); QCOMPARE(instanceCount, 3); - { QVariant second = myCarrier; - QCOMPARE(instanceCount, 3); + QCOMPARE(instanceCount, 4); second.detach(); QCOMPARE(instanceCount, 4); } @@ -2103,6 +2108,7 @@ void tst_QVariant::userType() QCOMPARE(qvariant_cast<int>(myCarrier), 42); } + // At this point all QVariants got destroyed and MyType objects too. QCOMPARE(instanceCount, 0); } @@ -2701,7 +2707,7 @@ void tst_QVariant::task172061_invalidDate() const struct WontCompare { - int x; + int x,y,z,q,w,e,r,t; }; Q_DECLARE_METATYPE(WontCompare); @@ -2952,7 +2958,12 @@ template<class T> void playWithVariant(const T &orig, bool isNull, const QString { QVariant v2 = v; - QCOMPARE(v2, v); + if (!(QTypeInfo<T>::isStatic && QTypeInfo<T>::isComplex)) { + // Type is movable so standard comparison algorithm in QVariant should work + // In a custom type QVariant is not aware of ==operator so it won't be called, + // which may cause problems especially visible when using a not-movable type + QCOMPARE(v2, v); + } QVERIFY(v2.isValid()); QCOMPARE(v2.isNull(), isNull); QCOMPARE(v2.toString(), toString); @@ -2964,7 +2975,12 @@ template<class T> void playWithVariant(const T &orig, bool isNull, const QString v = QVariant(); QCOMPARE(v3, v); v = v2; - QCOMPARE(v, v2); + if (!(QTypeInfo<T>::isStatic && QTypeInfo<T>::isComplex)) { + // Type is movable so standard comparison algorithm in QVariant should work + // In a custom type QVariant is not aware of ==operator so it won't be called, + // which may cause problems especially visible when using a not-movable type + QCOMPARE(v2, v); + } QCOMPARE(qvariant_cast<T>(v2), qvariant_cast<T>(v)); QCOMPARE(v2.toString(), toString); v3 = qVariantFromValue(orig); |