diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 28 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp | 12 |
2 files changed, 30 insertions, 10 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); diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 4d38aa1646..70396a75b3 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -80,8 +80,10 @@ void tst_Cmptest::compare_pointerfuncs() Q_DECLARE_METATYPE(QVariant) -class PhonyClass -{}; +struct PhonyClass +{ + int i; +}; void tst_Cmptest::compare_tostring_data() { @@ -108,9 +110,11 @@ void tst_Cmptest::compare_tostring_data() << QVariant(QVariant::Type(qRegisterMetaType<PhonyClass>("PhonyClass"))) ; + PhonyClass fake1 = {1}; + PhonyClass fake2 = {2}; QTest::newRow("both non-null user type") - << QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)0) - << QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)0) + << QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)&fake1) + << QVariant(qRegisterMetaType<PhonyClass>("PhonyClass"), (const void*)&fake2) ; } |