From a2e23bca0f2b43a26e2e489f83cfe2e521da63b9 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Feb 2021 11:11:28 +0100 Subject: [PATCH] QJsonObject: Fix operator<=() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had a copy-paste error there. Pick-to: 6.0 6.1 Change-Id: Ib1448197ac4f4641c6559f133f41dcf326f210f1 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/serialization/qjsonobject.h | 2 +- .../corelib/serialization/json/tst_qtjson.cpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index 1e6cc65227..e477345643 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -153,7 +153,7 @@ public: bool operator<(const iterator& other) const { Q_ASSERT(item.o == other.item.o); return item.index < other.item.index; } bool operator<=(const iterator& other) const - { Q_ASSERT(item.o == other.item.o); return item.index < other.item.index; } + { Q_ASSERT(item.o == other.item.o); return item.index <= other.item.index; } bool operator>(const iterator& other) const { return !(*this <= other); } bool operator>=(const iterator& other) const { return !(*this < other); } diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index b5aa1d7331..afd3303298 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -170,6 +170,8 @@ private Q_SLOTS: void fromToVariantConversions_data(); void fromToVariantConversions(); + void testIteratorComparison(); + private: QString testDataDir; }; @@ -3520,5 +3522,34 @@ void tst_QtJson::fromToVariantConversions() } } +void tst_QtJson::testIteratorComparison() +{ + QJsonObject t = QJsonObject::fromVariantHash({ + { QStringLiteral("a"), QVariant(12) }, + { QStringLiteral("b"), QVariant(13) } + }); + + QVERIFY(t.begin() == t.begin()); + QVERIFY(t.begin() <= t.begin()); + QVERIFY(t.begin() >= t.begin()); + QVERIFY(!(t.begin() != t.begin())); + QVERIFY(!(t.begin() < t.begin())); + QVERIFY(!(t.begin() > t.begin())); + + QVERIFY(!(t.begin() == t.end())); + QVERIFY(t.begin() <= t.end()); + QVERIFY(!(t.begin() >= t.end())); + QVERIFY(t.begin() != t.end()); + QVERIFY(t.begin() < t.end()); + QVERIFY(!(t.begin() > t.end())); + + QVERIFY(!(t.end() == t.begin())); + QVERIFY(!(t.end() <= t.begin())); + QVERIFY(t.end() >= t.begin()); + QVERIFY(t.end() != t.begin()); + QVERIFY(!(t.end() < t.begin())); + QVERIFY(t.end() > t.begin()); +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc"