summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorClemens Sielaff <git@clemens-sielaff.com>2016-07-24 11:21:34 +1200
committerJędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>2016-08-03 11:16:35 +0000
commit2a24c3c268d443fb260d731d9f65b57726a40354 (patch)
tree79edca5f870869a2f22fd634242ed948ae157208 /tests
parentdbb5c95f4d80644c6273b3adbe0148cdf30710d2 (diff)
Fixed Bug in QVariant comparison when containing QStringLists
As it were, QStringLists were not handled explicitly when comparing QVariants. If both QStringLists contained only a single entry, they were treated as QStrings - if both QStringLists were empty, there were equal (correctly so) - but if one of the QStringLists had more than one entry, the compare function fell through to returning always 1. As discussed here: https://stackoverflow.com/a/38492467/3444217 Added rich comparison tests for all non-numerical, non-recursive QVariants that support them (except QModelIndex and QPersistentModelIndex) Task-number: QTBUG-54893 Change-Id: Icc5480d9ba056ee5efe83da566c5829caa1509d7 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 76230ccec8..509eed231d 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -279,6 +279,7 @@ private slots:
void metaEnums();
void compareSanity_data();
void compareSanity();
+ void compareRich();
void accessSequentialContainerKey();
@@ -4745,6 +4746,60 @@ void tst_QVariant::compareSanity()
}
}
+static void richComparison(const QVariant& less, const QVariant& more)
+{
+ QVERIFY(less.type() == more.type());
+
+ QVERIFY(less < more);
+ QVERIFY(!(more < less));
+
+ QVERIFY(more > less);
+ QVERIFY(!(less > more));
+
+ QVERIFY(less <= more);
+ QVERIFY(!(more <= less));
+ QVERIFY(less <= less);
+
+ QVERIFY(more >= less);
+ QVERIFY(!(less >= more));
+ QVERIFY(more >= more);
+}
+
+void tst_QVariant::compareRich()
+{
+ richComparison(QUuid("{49d8ad2a-2ee8-4c3d-949f-1b5a3765ddf0}"),
+ QUuid("{f6d56824-16e9-4543-a375-add2877c2d05}"));
+ richComparison(QByteArray::fromRawData("a", 1),
+ QByteArray::fromRawData("b", 1));
+ richComparison(QStringLiteral("a"), QStringLiteral("b"));
+ richComparison(QLatin1String("a"), QLatin1String("b"));
+ richComparison(QChar('a'), QChar('b'));
+ richComparison(QDate(2016, 7, 23), QDate(2016, 7, 24));
+ richComparison(QTime(0, 0), QTime(0, 1));
+ richComparison(QDateTime(QDate(2016, 7, 23), QTime(0, 0)),
+ QDateTime(QDate(2016, 7, 23), QTime(0, 1)));
+
+ richComparison(QStringList(), QStringList() << QStringLiteral("a"));
+ richComparison(QStringList(), QStringList() << QStringLiteral("a")
+ << QStringLiteral("b"));
+ richComparison(QStringList() << QStringLiteral("a"),
+ QStringList() << QStringLiteral("b"));
+ richComparison(QStringList() << QStringLiteral("a"),
+ QStringList() << QStringLiteral("b")
+ << QStringLiteral("c"));
+ richComparison(QStringList() << QStringLiteral("a")
+ << QStringLiteral("c"),
+ QStringList() << QStringLiteral("b"));
+ richComparison(QStringList() << QStringLiteral("a")
+ << QStringLiteral("c"),
+ QStringList() << QStringLiteral("b")
+ << QStringLiteral("d"));
+ richComparison(QStringList() << QStringLiteral("a")
+ << QStringLiteral("c"),
+ QStringList() << QStringLiteral("a")
+ << QStringLiteral("d"));
+}
+
void tst_QVariant::accessSequentialContainerKey()
{
QString nameResult;