diff options
Diffstat (limited to 'tests/auto/corelib/io/qurlquery')
-rw-r--r-- | tests/auto/corelib/io/qurlquery/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp | 115 |
2 files changed, 107 insertions, 17 deletions
diff --git a/tests/auto/corelib/io/qurlquery/CMakeLists.txt b/tests/auto/corelib/io/qurlquery/CMakeLists.txt index 80a8ba1a3c..c9f5491416 100644 --- a/tests/auto/corelib/io/qurlquery/CMakeLists.txt +++ b/tests/auto/corelib/io/qurlquery/CMakeLists.txt @@ -1,15 +1,20 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qurlquery.pro. - ##################################################################### ## tst_qurlquery Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qurlquery LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qurlquery SOURCES tst_qurlquery.cpp LIBRARIES Qt::CorePrivate + Qt::TestPrivate ) diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp index 15c0474eb0..8360bdbe28 100644 --- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp +++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp @@ -1,9 +1,11 @@ // Copyright (C) 2022 The Qt Company Ltd. // Copyright (C) 2012 Intel Corporation. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtCore/QUrlQuery> #include <QTest> +#include <QtTest/private/qcomparisontesthelper_p.h> + +#include <QtCore/QUrlQuery> typedef QList<QPair<QString, QString> > QueryItems; Q_DECLARE_METATYPE(QueryItems) @@ -22,6 +24,9 @@ public: } private Q_SLOTS: + void compareCompiles(); + void compareEquality_data(); + void compareEquality(); void constructing(); void addRemove(); void multiAddRemove(); @@ -68,9 +73,12 @@ static QByteArray prettyList(const QueryItems &items) static bool compare(const QueryItems &actual, const QueryItems &expected, const char *actualStr, const char *expectedStr, const char *file, int line) { + auto formatter = [](const void *val) -> const char * { + const QueryItems items = *static_cast<const QueryItems *>(val); + return qstrdup(prettyList(items).constData()); + }; return QTest::compare_helper(actual == expected, "Compared values are not the same", - [&actual] { return qstrdup(prettyList(actual).constData()); }, - [&expected] { return qstrdup(prettyList(expected).constData()); }, + &actual, &expected, formatter, formatter, actualStr, expectedStr, file, line); } @@ -119,6 +127,48 @@ static QUrlQuery emptyQuery() return QUrlQuery(); } +void tst_QUrlQuery::compareCompiles() +{ + QTestPrivate::testEqualityOperatorsCompile<QUrlQuery>(); +} + +void tst_QUrlQuery::compareEquality_data() +{ + QTest::addColumn<QUrlQuery>("url1"); + QTest::addColumn<QUrlQuery>("url2"); + QTest::addColumn<bool>("equal"); + + QTest::newRow("empty-empty") << QUrlQuery() << QUrlQuery() << true; + + QUrlQuery notEmpty; + notEmpty.addQueryItem("a", "b"); + QTest::newRow("empty-notEmpty") << QUrlQuery() << notEmpty << false; + + QUrlQuery notEmpty_copy = notEmpty; + QTest::newRow("sameItems") << notEmpty_copy << notEmpty << true; + + QUrlQuery notEmpty_modified = notEmpty; + notEmpty_modified.addQueryItem("c", "d"); + QTest::newRow("addedItems") << notEmpty_copy << notEmpty_modified << false; + + QUrlQuery notEmpty2; + notEmpty2.addQueryItem("c", "d"); + QTest::newRow("differentItems") << notEmpty2 << notEmpty << false; + + QUrlQuery differentPairDelimiters; + differentPairDelimiters.setQueryDelimiters('(', ')'); + QTest::newRow("defaultDelimiters-differentDelimiters") << QUrlQuery() << differentPairDelimiters + << false; +} + +void tst_QUrlQuery::compareEquality() +{ + QFETCH(QUrlQuery, url1); + QFETCH(QUrlQuery, url2); + QFETCH(bool, equal); + QT_TEST_EQUALITY_OPS(url1, url2, equal); +} + void tst_QUrlQuery::constructing() { QUrlQuery empty; @@ -137,7 +187,7 @@ void tst_QUrlQuery::constructing() QVERIFY(!copy.isDetached()); QCOMPARE(copy, empty); QCOMPARE(qHash(copy), qHash(empty)); - QVERIFY(!(copy != empty)); + QT_TEST_EQUALITY_OPS(copy, empty, true); copy = empty; QCOMPARE(copy, empty); @@ -169,20 +219,50 @@ void tst_QUrlQuery::constructing() other.addQueryItem("a", "b"); QVERIFY(!other.isEmpty()); QVERIFY(other.isDetached()); - QVERIFY(other != empty); - QVERIFY(!(other == empty)); + QCOMPARE_NE(other, empty); + QT_TEST_EQUALITY_OPS(other, empty, false); + // copy-construct QUrlQuery copy(other); QCOMPARE(copy, other); copy.clear(); QVERIFY(copy.isEmpty()); - QVERIFY(copy != other); + QCOMPARE_NE(copy, other); + // copy-assign copy = other; QVERIFY(!copy.isEmpty()); QCOMPARE(copy, other); + // move-construct + QUrlQuery moved(std::move(other)); + QCOMPARE(moved, copy); + + // self move-assign + { + auto &self = moved; // prevent -Wself-move + moved = std::move(self); + } + QCOMPARE(moved, copy); + + // self move-assign of moved-from (Hinnant Criterion) + { + auto &self = other; // prevent -Wself-move + other = std::move(self); + } + // shouldn't crash; here, or further down + + // copy-assign to moved-from object + other = copy; + QCOMPARE(other, copy); + QCOMPARE(other, moved); + + // move-assign + moved = std::move(other); + QCOMPARE(moved, copy); + + // (move-)assign default-constructed copy = QUrlQuery(); QVERIFY(copy.isEmpty()); @@ -210,12 +290,14 @@ void tst_QUrlQuery::constructing() void tst_QUrlQuery::addRemove() { QUrlQuery query; + QCOMPARE(query, query); { // one item query.addQueryItem("a", "b"); QVERIFY(!query.isEmpty()); QVERIFY(query.hasQueryItem("a")); + QCOMPARE_NE(query, QUrlQuery()); QCOMPARE(query.queryItemValue("a"), QString("b")); QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b"); @@ -226,6 +308,7 @@ void tst_QUrlQuery::addRemove() } QUrlQuery original = query; + QCOMPARE(query, original); { // two items @@ -242,8 +325,8 @@ void tst_QUrlQuery::addRemove() QVERIFY(allItems.contains(qItem("a", "b"))); QVERIFY(allItems.contains(qItem("c", "d"))); - QVERIFY(query != original); - QVERIFY(!(query == original)); + QCOMPARE_NE(query, original); + QT_TEST_EQUALITY_OPS(query, original, false); } { @@ -266,7 +349,7 @@ void tst_QUrlQuery::addRemove() QCOMPARE(allItems.at(0).second, QString("b")); QCOMPARE(query, original); - QVERIFY(!(query != original)); + QT_TEST_EQUALITY_OPS(query, original, true); QCOMPARE(qHash(query), qHash(original)); } @@ -289,8 +372,8 @@ void tst_QUrlQuery::addRemove() QVERIFY(allItems.contains(qItem("a", "b"))); QVERIFY(allItems.contains(qItem("e", emptyButNotNull))); - QVERIFY(query != original); - QVERIFY(!(query == original)); + QCOMPARE_NE(query, original); + QT_TEST_EQUALITY_OPS(query, original, false); } { @@ -298,6 +381,9 @@ void tst_QUrlQuery::addRemove() query.removeQueryItem("a"); query.removeQueryItem("e"); QVERIFY(query.isEmpty()); + QVERIFY(query.isDetached()); + QCOMPARE_NE(query, original); + QCOMPARE(query, QUrlQuery()); } } @@ -500,12 +586,11 @@ void tst_QUrlQuery::reconstructQuery_data() baselist << qItem("a", "b") << qItem("c", "d"); QTest::newRow("2-ab-cd") << "a=b&c=d" << baselist; - // the same entry multiply defined + // The same entry multiply defined QTest::newRow("2-a-a") << "a&a" << (QueryItems() << qItem("a", QString()) << qItem("a", QString())); QTest::newRow("2-ab-ab") << "a=b&a=b" << (QueryItems() << qItem("a", "b") << qItem("a", "b")); QTest::newRow("2-ab-ac") << "a=b&a=c" << (QueryItems() << qItem("a", "b") << qItem("a", "c")); QTest::newRow("2-ac-ab") << "a=c&a=b" << (QueryItems() << qItem("a", "c") << qItem("a", "b")); - QTest::newRow("2-ab-cd") << "a=b&c=d" << (QueryItems() << qItem("a", "b") << qItem("c", "d")); QTest::newRow("2-cd-ab") << "c=d&a=b" << (QueryItems() << qItem("c", "d") << qItem("a", "b")); QueryItems list2 = baselist + qItem("somekey", QString()); |