Test QVariant copy with a user type instead of a QtNetwork type.
authorStephen Kelly <stephen.kelly@kdab.com>
Fri, 13 Jul 2012 18:18:40 +0000 (20:18 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sat, 14 Jul 2012 23:23:25 +0000 (01:23 +0200)
Change-Id: I78acc8a843eb12a2606f491d1a29e1bcd408d60f
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
tests/auto/corelib/kernel/qvariant/qvariant.pro
tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp

index b591a18..522a915 100644 (file)
@@ -1,6 +1,6 @@
 CONFIG += testcase
 CONFIG += parallel_test
 TARGET = tst_qvariant
-QT += widgets network testlib
+QT += widgets testlib
 SOURCES = tst_qvariant.cpp
 RESOURCES += qvariant.qrc
index ca62af2..0840e6a 100644 (file)
@@ -43,7 +43,6 @@
 
 #include <qvariant.h>
 #include <qbitarray.h>
-#include <qhostaddress.h>
 #include <qdatetime.h>
 #include <qmap.h>
 #include <qiodevice.h>
@@ -2971,17 +2970,28 @@ void tst_QVariant::timeToDateTime() const
     QVERIFY(!val.toDateTime().isValid());
 }
 
-Q_DECLARE_METATYPE(QHostAddress)
+struct CustomComparable
+{
+    CustomComparable(int value = 0) : myValue(value) {}
+    int myValue;
+
+    bool operator==(const CustomComparable &other) const
+    { return other.myValue == myValue; }
+};
+
+Q_DECLARE_METATYPE(CustomComparable)
 
 void tst_QVariant::copyingUserTypes() const
 {
     QVariant var;
-    QVariant var3;
-    const QHostAddress ha("127.0.0.1");
-    var.setValue(ha);
-    var3 = var;
-
-    QCOMPARE(qvariant_cast<QHostAddress>(var3), ha);
+    QVariant varCopy;
+    const CustomComparable userType = CustomComparable(42);
+    var.setValue(userType);
+    varCopy = var;
+
+    const CustomComparable copiedType = qvariant_cast<CustomComparable>(varCopy);
+    QCOMPARE(copiedType, userType);
+    QCOMPARE(copiedType.myValue, 42);
 }
 
 void tst_QVariant::convertBoolToByteArray() const