From cd5dd8b95bbda1e9531af52c251ea926f125c8ea Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Thu, 14 Mar 2024 17:28:57 +0100 Subject: Xml: use new comparison helper macros New comparison macros are used for following classes: -QXmlStreamAttribute -QXmlStreamNamespaceDeclaration -QXmlStreamNotationDeclaration -QXmlStreamEntityDeclaration Replace public operators operator==(), operator!=() of classes to friend methods comparesEqual(); Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Add checkStreamNotationDeclarations()/checkStreamEntityDeclarations() test-cases to test change. Task-number: QTBUG-120300 Change-Id: I0b5642b2e23cc21ede7bc4888f0a9bddd6c08d07 Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira --- .../serialization/qxmlstream/CMakeLists.txt | 1 + .../serialization/qxmlstream/tst_qxmlstream.cpp | 78 +++++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/serialization/qxmlstream') diff --git a/tests/auto/corelib/serialization/qxmlstream/CMakeLists.txt b/tests/auto/corelib/serialization/qxmlstream/CMakeLists.txt index e37820fec5..30c86491ff 100644 --- a/tests/auto/corelib/serialization/qxmlstream/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qxmlstream/CMakeLists.txt @@ -26,6 +26,7 @@ qt_internal_add_test(tst_qxmlstream LIBRARIES Qt::Network Qt::CorePrivate + Qt::TestPrivate TESTDATA ${test_data} ${tokenError} diff --git a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp index 9a28849cbb..3fa812193f 100644 --- a/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -542,6 +543,7 @@ public: private slots: void initTestCase(); void cleanupTestCase(); + void compareCompiles(); void runTestSuite(); void reportFailures() const; void reportFailures_data(); @@ -593,6 +595,8 @@ private slots: void tokenErrorHandling_data() const; void tokenErrorHandling() const; + void checkStreamNotationDeclarations() const; + void checkStreamEntityDeclarations() const; private: static QByteArray readFile(const QString &filename); @@ -636,6 +640,14 @@ void tst_QXmlStream::cleanupTestCase() { } +void tst_QXmlStream::compareCompiles() +{ + QTestPrivate::testEqualityOperatorsCompile(); + QTestPrivate::testEqualityOperatorsCompile(); + QTestPrivate::testEqualityOperatorsCompile(); + QTestPrivate::testEqualityOperatorsCompile(); +} + void tst_QXmlStream::runTestSuite() { QFile file(m_tempDir.filePath(catalogFile)); @@ -886,12 +898,17 @@ void tst_QXmlStream::addExtraNamespaceDeclarations() } { QXmlStreamReader xml(data); - xml.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("undeclared", "blabla")); - xml.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("undeclared_too", "foofoo")); + QXmlStreamNamespaceDeclaration undeclared("undeclared", "blabla"); + QXmlStreamNamespaceDeclaration undeclared_too("undeclared_too", "blabla"); + xml.addExtraNamespaceDeclaration(undeclared); + xml.addExtraNamespaceDeclaration(undeclared_too); while (!xml.atEnd()) { xml.readNext(); } QVERIFY2(!xml.hasError(), xml.errorString().toLatin1().constData()); + QT_TEST_EQUALITY_OPS(undeclared, undeclared_too, false); + undeclared = undeclared_too; + QT_TEST_EQUALITY_OPS(undeclared, undeclared_too, true); } } @@ -1346,6 +1363,15 @@ void tst_QXmlStream::hasAttribute() const reader.readNext(); QVERIFY(!reader.hasError()); + + QXmlStreamAttribute attrValue1(QLatin1String("http://example.com/"), QString::fromLatin1("attr1")); + QXmlStreamAttribute attrValue2 = atts.at(0); + QT_TEST_EQUALITY_OPS(atts.at(0), QXmlStreamAttribute(), false); + QT_TEST_EQUALITY_OPS(atts.at(0), attrValue1, false); + QT_TEST_EQUALITY_OPS(atts.at(0), attrValue2, true); + QT_TEST_EQUALITY_OPS(attrValue1, attrValue2, false); + attrValue1 = attrValue2; + QT_TEST_EQUALITY_OPS(attrValue1, attrValue2, true); } void tst_QXmlStream::writeWithUtf8Codec() const @@ -1927,4 +1953,52 @@ void tst_QXmlStream::tokenErrorHandling() const QVERIFY(reader.errorString().contains(errorKeyWord)); } +void tst_QXmlStream::checkStreamNotationDeclarations() const +{ + QString fileName("12.xml"); + const QDir dir(QFINDTESTDATA("data")); + QFile file(dir.absoluteFilePath(fileName)); + if (!file.exists()) + QSKIP(QObject::tr("Testfile %1 not found.").arg(fileName).toUtf8().constData()); + file.open(QIODevice::ReadOnly); + QXmlStreamReader reader(&file); + while (!reader.atEnd()) + reader.readNext(); + + QVERIFY(!reader.hasError()); + QXmlStreamNotationDeclaration notation1, notation2, notation3; + QT_TEST_EQUALITY_OPS(notation1, notation2, true); + const auto notationDeclarations = reader.notationDeclarations(); + if (notationDeclarations.count() >= 2) { + notation1 = notationDeclarations.at(0); + notation2 = notationDeclarations.at(1); + notation3 = notationDeclarations.at(1); + } + QT_TEST_EQUALITY_OPS(notation1, notation2, false); + QT_TEST_EQUALITY_OPS(notation3, notation2, true); +} + +void tst_QXmlStream::checkStreamEntityDeclarations() const +{ + QString fileName("5.xml"); + const QDir dir(QFINDTESTDATA("data")); + QFile file(dir.absoluteFilePath(fileName)); + if (!file.exists()) + QSKIP(QObject::tr("Testfile %1 not found.").arg(fileName).toUtf8().constData()); + file.open(QIODevice::ReadOnly); + QXmlStreamReader reader(&file); + while (!reader.atEnd()) + reader.readNext(); + + QVERIFY(!reader.hasError()); + QXmlStreamEntityDeclaration entity; + QT_TEST_EQUALITY_OPS(entity, QXmlStreamEntityDeclaration(), true); + + const auto entityDeclarations = reader.entityDeclarations(); + if (entityDeclarations.count() >= 2) { + entity = entityDeclarations.at(1); + QT_TEST_EQUALITY_OPS(entityDeclarations.at(0), entityDeclarations.at(1), false); + QT_TEST_EQUALITY_OPS(entity, entityDeclarations.at(1), true); + } +} #include "tst_qxmlstream.moc" -- cgit v1.2.3