diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-15 17:23:16 +0100 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-03-21 23:43:35 +0100 |
commit | 2499de88744c493bebda25c0135bd623ccf35729 (patch) | |
tree | 8ed42ea563b4c897f2b16e970283ffcc94444933 /tests/auto/corelib/serialization/json | |
parent | 587003c3ccf6f8abab9aa6e8131f5ff6ce368d8a (diff) |
QJsonArray: use new comparison helper macros
Replace public operators operator==(), operator!=() of
QJsonArray to friend methods comparesEqual().
Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current
comparison methods and replace them with a friend.
Add friend method comparesEqual(QJsonArray, QJsonValue)
to the QJsonArray class, to support comparison between QJsonArray
and QJsonValue elements, see test-case fromToVariantConversions()
Task-number: QTBUG-120300
Change-Id: I8440ca0761bede8551ff792bfa7f22e47b56fa79
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/serialization/json')
-rw-r--r-- | tests/auto/corelib/serialization/json/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/corelib/serialization/json/tst_qtjson.cpp | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/corelib/serialization/json/CMakeLists.txt b/tests/auto/corelib/serialization/json/CMakeLists.txt index 106b91daea..c73a99a3b8 100644 --- a/tests/auto/corelib/serialization/json/CMakeLists.txt +++ b/tests/auto/corelib/serialization/json/CMakeLists.txt @@ -26,6 +26,7 @@ qt_internal_add_test(tst_json tst_qtjson.cpp LIBRARIES Qt::CorePrivate + Qt::TestPrivate TESTDATA ${json_resource_files} ) diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp index 783138945e..cdc51ec140 100644 --- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp +++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> +#include <QtTest/private/qcomparisontesthelper_p.h> #include <QMap> #include <QVariantList> @@ -27,6 +28,7 @@ class tst_QtJson: public QObject private Q_SLOTS: void initTestCase(); + void compareCompiles(); void testValueSimple(); void testNumbers(); void testNumbers_2(); @@ -47,6 +49,8 @@ private Q_SLOTS: void testArrayNested(); void testArrayNestedEmpty(); void testArrayComfortOperators(); + void testArrayEquality_data(); + void testArrayEquality(); void testObjectNestedEmpty(); void testValueRef(); @@ -169,6 +173,12 @@ void tst_QtJson::initTestCase() testDataDir = QCoreApplication::applicationDirPath(); } +void tst_QtJson::compareCompiles() +{ + QTestPrivate::testEqualityOperatorsCompile<QJsonArray>(); + QTestPrivate::testEqualityOperatorsCompile<QJsonArray, QJsonValue>(); +} + void tst_QtJson::testValueSimple() { QJsonObject object; @@ -901,6 +911,36 @@ void tst_QtJson::testObjectNestedEmpty() QCOMPARE(object.value("inner").type(), QJsonValue::Object); } +void tst_QtJson::testArrayEquality_data() +{ + QTest::addColumn<QJsonArray>("array1"); + QTest::addColumn<QJsonArray>("array2"); + QTest::addColumn<bool>("expectedResult"); + QTest::addRow("QJsonArray(), QJsonArray{665, 666, 667}") + << QJsonArray() << QJsonArray{665, 666, 667} << false; + QTest::addRow("QJsonArray(), QJsonArray{}") + << QJsonArray() << QJsonArray{} <<true; + QTest::addRow("QJsonArray(), QJsonArray{123, QLatin1String(\"foo\")}") + << QJsonArray() << QJsonArray{123, QLatin1String("foo")} << false; + QTest::addRow( + "QJsonArray{123,QLatin1String(\"foo\")}, QJsonArray{123,QLatin1String(\"foo\")}") + << QJsonArray{123, QLatin1String("foo")} + << QJsonArray{123, QLatin1String("foo")} + << true; +} + +void tst_QtJson::testArrayEquality() +{ + QFETCH(QJsonArray, array1); + QFETCH(QJsonArray, array2); + QFETCH(bool, expectedResult); + + QJsonValue value = QJsonValue(array1); + + QT_TEST_EQUALITY_OPS(array1, array2, expectedResult); + QT_TEST_EQUALITY_OPS(value, array2, expectedResult); +} + void tst_QtJson::testArrayComfortOperators() { QJsonArray first; |