summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-10-25 12:05:27 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2019-11-26 09:07:26 +0100
commitccc2133c648ca531630095f3f1016e2026d7e34e (patch)
tree22ed29871c17b8a87048249e92c399f8b01546cc /tests
parentf0443984b84dea782ccd06dbce59808d55b15dbe (diff)
Port QDomDocument to QXmlStreamReader
Reimplement QDomDocument using QXmlStreamReader and switch to the new implementation starting from Qt 6. The changes in the behavior are reflected in tests: some test cases which were marked as "expected to fail" are now passing. Task-number: QTBUG-76178 Change-Id: I5ace2f13c036a9a778de922b47a1ce35957ce5f6 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp6
-rw-r--r--tests/auto/xml/dom/qdom/tst_qdom.cpp48
2 files changed, 48 insertions, 6 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 52e56feb5a..0e9f94ab2b 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -1793,6 +1793,12 @@ void tst_QTextDocument::toHtml()
QCOMPARE(output, expectedOutput);
QDomDocument document;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ QEXPECT_FAIL("charfmt-for-list-item",
+ "The attribute \"style\" is redefined in the generated HTML, which is not valid "
+ "according to XML standard. The new QDomDocument implementation follows the XML "
+ "standard.", Continue);
+#endif
QVERIFY2(document.setContent(output), "Output was not valid XML");
}
diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp
index 99639df5b0..ab62307704 100644
--- a/tests/auto/xml/dom/qdom/tst_qdom.cpp
+++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp
@@ -173,6 +173,8 @@ void tst_QDom::setContent_data()
" </b3>\n"
"</a1>\n");
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ // These configurations cannot be supported by the QXmlStreamReader-based implementation
QTest::newRow( "02" ) << doc01
<< QString("http://trolltech.com/xml/features/report-whitespace-only-CharData").split(' ')
<< QStringList()
@@ -227,6 +229,7 @@ void tst_QDom::setContent_data()
" <c1/>\n"
" </b3>\n"
"</a1>\n");
+#endif
QTest::newRow("05") << QString("<message>\n"
" <body>&lt;b&gt;foo&lt;/b&gt;>]]&gt;</body>\n"
@@ -242,6 +245,8 @@ void tst_QDom::setContent()
{
QFETCH( QString, doc );
+ QDomDocument domDoc;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QXmlInputSource source;
source.setData( doc );
@@ -258,8 +263,11 @@ void tst_QDom::setContent()
reader.setFeature( *it, false );
}
- QDomDocument domDoc;
QVERIFY( domDoc.setContent( &source, &reader ) );
+#else
+ QXmlStreamReader reader(doc);
+ QVERIFY(domDoc.setContent(&reader, true));
+#endif
QString eRes;
QTextStream ts( &eRes, QIODevice::WriteOnly );
@@ -1475,8 +1483,9 @@ void tst_QDom::normalizeAttributes() const
QDomDocument doc;
QVERIFY(doc.setContent(&buffer, true));
- // ### Qt 5: fix this, if we keep QDom at all
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QEXPECT_FAIL("", "The parser doesn't perform Attribute Value Normalization. Fixing that would change behavior.", Continue);
+#endif
QCOMPARE(doc.documentElement().attribute(QLatin1String("attribute")), QString::fromLatin1("a a"));
}
@@ -1517,9 +1526,10 @@ void tst_QDom::serializeNamespaces() const
"<b:element b:name=''/>"
"</doc>";
+ QDomDocument doc;
QByteArray ba(input);
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QBuffer buffer(&ba);
-
QVERIFY(buffer.open(QIODevice::ReadOnly));
QXmlInputSource source(&buffer);
@@ -1527,8 +1537,11 @@ void tst_QDom::serializeNamespaces() const
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
- QDomDocument doc;
QVERIFY(doc.setContent(&source, &reader));
+#else
+ QXmlStreamReader streamReader(input);
+ QVERIFY(doc.setContent(&streamReader, true));
+#endif
const QByteArray serialized(doc.toByteArray());
@@ -1552,7 +1565,9 @@ void tst_QDom::flagInvalidNamespaces() const
QDomDocument doc;
QVERIFY(!doc.setContent(QString::fromLatin1(input, true)));
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QEXPECT_FAIL("", "The parser doesn't flag identical qualified attribute names. Fixing this would change behavior.", Continue);
+#endif
QVERIFY(!doc.setContent(QString::fromLatin1(input)));
}
@@ -1563,7 +1578,9 @@ void tst_QDom::flagUndeclaredNamespace() const
"<b:element b:name=''/>"
"</a:doc>";
+ QDomDocument doc;
QByteArray ba(input);
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QBuffer buffer(&ba);
QVERIFY(buffer.open(QIODevice::ReadOnly));
@@ -1573,9 +1590,12 @@ void tst_QDom::flagUndeclaredNamespace() const
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
- QDomDocument doc;
QEXPECT_FAIL("", "The parser doesn't flag not declared prefixes. Fixing this would change behavior.", Continue);
QVERIFY(!doc.setContent(&source, &reader));
+#else
+ QXmlStreamReader streamReader(ba);
+ QVERIFY(!doc.setContent(&streamReader, true));
+#endif
}
void tst_QDom::indentComments() const
@@ -1642,7 +1662,9 @@ void tst_QDom::reportDuplicateAttributes() const
QDomDocument dd;
bool isSuccess = dd.setContent(QLatin1String("<test x=\"1\" x=\"2\"/>"));
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QEXPECT_FAIL("", "The parser doesn't flag duplicate attributes. Fixing this would change behavior.", Continue);
+#endif
QVERIFY2(!isSuccess, "Duplicate attributes are well-formedness errors, and should be reported as such.");
}
@@ -1842,10 +1864,15 @@ void tst_QDom::doubleNamespaceDeclarations() const
QFile file(testFile);
QVERIFY(file.open(QIODevice::ReadOnly));
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QXmlSimpleReader reader;
QXmlInputSource source(&file);
QVERIFY(doc.setContent(&source, &reader));
+#else
+ QXmlStreamReader streamReader(&file);
+ QVERIFY(doc.setContent(&streamReader, true));
+#endif
// tst_QDom relies on a specific QHash ordering, see QTBUG-25071
QString docAsString = doc.toString(0);
@@ -1862,11 +1889,15 @@ void tst_QDom::setContentQXmlReaderOverload() const
{
QDomDocument doc;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QXmlSimpleReader reader;
QXmlInputSource data;
data.setData(QByteArray("<e/>"));
-
doc.setContent(&data, true);
+#else
+ QXmlStreamReader streamReader(QByteArray("<e/>"));
+ doc.setContent(&streamReader, true);
+#endif
QCOMPARE(doc.documentElement().nodeName(), QString::fromLatin1("e"));
}
@@ -1961,6 +1992,10 @@ void tst_QDom::setContentWhitespace_data() const
void tst_QDom::taskQTBUG4595_dontAssertWhenDocumentSpecifiesUnknownEncoding() const
{
+ // QXmlStreamReader fails to read XML documents with unknown encoding. It
+ // needs to be modified if we want to support this case with the QXmlStreamReader-based
+ // implementation.
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QString xmlWithUnknownEncoding("<?xml version='1.0' encoding='unknown-encoding'?>"
"<foo>"
" <bar>How will this sentence be handled?</bar>"
@@ -1970,6 +2005,7 @@ void tst_QDom::taskQTBUG4595_dontAssertWhenDocumentSpecifiesUnknownEncoding() co
QString dontAssert = d.toString(); // this should not assert
QVERIFY(true);
+#endif
}
void tst_QDom::cloneDTD_QTBUG8398() const