From adfb66d02a8a0987672ae2ce5520ec22ec4b69b8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 13 Jul 2012 20:18:40 +0200 Subject: [PATCH] Test QVariant copy with a user type instead of a QtNetwork type. Change-Id: I78acc8a843eb12a2606f491d1a29e1bcd408d60f Reviewed-by: Olivier Goffart --- .../auto/corelib/kernel/qvariant/qvariant.pro | 2 +- .../corelib/kernel/qvariant/tst_qvariant.cpp | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/auto/corelib/kernel/qvariant/qvariant.pro b/tests/auto/corelib/kernel/qvariant/qvariant.pro index b591a18174..522a9155d2 100644 --- a/tests/auto/corelib/kernel/qvariant/qvariant.pro +++ b/tests/auto/corelib/kernel/qvariant/qvariant.pro @@ -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 diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index ca62af2940..0840e6a7fb 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -43,7 +43,6 @@ #include #include -#include #include #include #include @@ -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; + QVariant varCopy; + const CustomComparable userType = CustomComparable(42); + var.setValue(userType); + varCopy = var; - QCOMPARE(qvariant_cast(var3), ha); + const CustomComparable copiedType = qvariant_cast(varCopy); + QCOMPARE(copiedType, userType); + QCOMPARE(copiedType.myValue, 42); } void tst_QVariant::convertBoolToByteArray() const