diff options
Diffstat (limited to 'tests/auto/xml/dom/qdom/tst_qdom.cpp')
-rw-r--r-- | tests/auto/xml/dom/qdom/tst_qdom.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index 1a26376456..3a947f4bff 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -34,6 +34,7 @@ #include <QFile> #include <QList> #include <QRegExp> +#include <QScopeGuard> #include <QTextStream> #include <QtTest/QtTest> #include <QtXml> @@ -85,6 +86,7 @@ private slots: void invalidQualifiedName(); void invalidCharData_data(); void invalidCharData(); + void nonBMPCharacters(); void roundTripAttributes() const; void normalizeEndOfLine() const; @@ -116,6 +118,8 @@ private slots: void cloneDTD_QTBUG8398() const; void DTDNotationDecl(); void DTDEntityDecl(); + void DTDInternalSubset() const; + void DTDInternalSubset_data() const; void QTBUG49113_dontCrashWithNegativeIndex() const; void cleanupTestCase() const; @@ -1392,6 +1396,10 @@ void tst_QDom::invalidCharData_data() QTest::newRow( "f<o&o" ) << QString("f<o&o") << true << true << true << QString("f<o&o"); QTest::newRow( "empty" ) << QString() << true << true << true << QString(); QTest::newRow("f\\x07o\\x02")<< QString("f\x07o\x02")<< true << true << false << QString("fo"); + + const QChar pair[2] = { QChar(0xdc00), QChar(0xe000) }; + QString invalid(pair, 2); + QTest::newRow("\\xdc00\\xe000") << invalid << true << true << false << invalid.right(1); } void tst_QDom::invalidCharData() @@ -1435,6 +1443,22 @@ void tst_QDom::invalidCharData() } } +void tst_QDom::nonBMPCharacters() +{ + const auto invalidDataPolicy = QDomImplementation::invalidDataPolicy(); + auto resetInvalidDataPolicy = qScopeGuard( + [invalidDataPolicy] { QDomImplementation::setInvalidDataPolicy(invalidDataPolicy); }); + QDomImplementation::setInvalidDataPolicy(QDomImplementation::DropInvalidChars); + + const QString input = QStringLiteral("<text>Supplementary Plane: 𝄞 😂 🀄 🀶 🃪 🃋</text>"); + + QString errorMsg; + QDomDocument doc; + doc.setContent(input, &errorMsg); + QVERIFY(errorMsg.isEmpty()); + QCOMPARE(doc.toString(-1), input); +} + void tst_QDom::roundTripAttributes() const { /* Create an attribute via the QDom API with weird whitespace content. */ @@ -2114,5 +2138,69 @@ void tst_QDom::QTBUG49113_dontCrashWithNegativeIndex() const QVERIFY(node.isNull()); } +void tst_QDom::DTDInternalSubset() const +{ + QFETCH( QString, doc ); + QFETCH( QString, internalSubset ); + QXmlStreamReader reader(doc); + QDomDocument document; + QVERIFY(document.setContent(&reader, true)); + + QCOMPARE(document.doctype().internalSubset(), internalSubset); +} + +void tst_QDom::DTDInternalSubset_data() const +{ + QTest::addColumn<QString>("doc"); + QTest::addColumn<QString>("internalSubset"); + + QTest::newRow("data1") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note SYSTEM '/[abcd].dtd'>\n" + "<note/>\n" + << "" ; + + QTest::newRow("data2") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note PUBLIC '-/freedesktop' 'https://[abcd].dtd'>\n" + "<note/>\n" + << "" ; + + const QString internalSubset0( + "<!-- open brackets comment [ -->\n" + "<!-- colse brackets comment ] -->\n" + ); + QTest::newRow("data3") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note [" + + internalSubset0 + + "]>\n" + "<note/>\n" + << internalSubset0; + + const QString internalSubset1( + "<!ENTITY obra '['>\n" + "<!ENTITY cbra ']'>\n" + ); + QTest::newRow("data4") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note [" + + internalSubset1 + + "]>\n" + "<note/>\n" + << internalSubset1; + + QTest::newRow("data5") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note PUBLIC '-/freedesktop' 'https://[abcd].dtd' [" + + internalSubset0 + + "]>\n" + "<note/>\n" + << internalSubset0; + + QTest::newRow("data6") << "<?xml version='1.0'?>\n" + "<!DOCTYPE note PUBLIC '-/freedesktop' " + "'2001:db8:130F:0000:0000:09C0:876A:130B://[abcd].dtd' [" + + internalSubset0 + + "]>\n" + "<note/>\n" + << internalSubset0; +} + QTEST_MAIN(tst_QDom) #include "tst_qdom.moc" |