diff options
Diffstat (limited to 'tests/auto/xml/dom/qdom/tst_qdom.cpp')
-rw-r--r-- | tests/auto/xml/dom/qdom/tst_qdom.cpp | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index aa03106270..b73dbc49e2 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// 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 <QBuffer> @@ -15,6 +15,7 @@ #include <QtXml> #include <QVariant> #include <cmath> +#include <QtXml/private/qdom_p.h> QT_FORWARD_DECLARE_CLASS(QDomDocument) QT_FORWARD_DECLARE_CLASS(QDomNode) @@ -105,6 +106,8 @@ private slots: void DTDInternalSubset() const; void DTDInternalSubset_data() const; void QTBUG49113_dontCrashWithNegativeIndex() const; + void standalone(); + void splitTextLeakMemory() const; void cleanupTestCase() const; @@ -1949,7 +1952,7 @@ void tst_QDom::germanUmlautToFile() const QString name(QLatin1String("german")); name += QChar(0xFC); name += QLatin1String("umlaut"); - QCOMPARE(name.length(), 13); + QCOMPARE(name.size(), 13); QDomDocument d("test"); d.appendChild(d.createElement(name)); @@ -1968,7 +1971,7 @@ void tst_QDom::germanUmlautToFile() const const QByteArray in(inFile.readAll()); /* Check that it was wwritten out correctly. */ - QCOMPARE(in.length(), 34); + QCOMPARE(in.size(), 34); QCOMPARE(in, baseline.toUtf8()); inFile.close(); @@ -2011,15 +2014,8 @@ void tst_QDom::doubleNamespaceDeclarations() const QXmlStreamReader streamReader(&file); QVERIFY(doc.setContent(&streamReader, QDomDocument::ParseOption::UseNamespaceProcessing)); - // tst_QDom relies on a specific QHash ordering, see QTBUG-25071 QString docAsString = doc.toString(0); - QVERIFY(docAsString == QString::fromLatin1("<a>\n<b p:c=\"\" xmlns:p=\"NS\" p:d=\"\"/>\n</a>\n") || - docAsString == QString::fromLatin1("<a>\n<b p:c=\"\" p:d=\"\" xmlns:p=\"NS\"/>\n</a>\n") || - docAsString == QString::fromLatin1("<a>\n<b p:d=\"\" p:c=\"\" xmlns:p=\"NS\"/>\n</a>\n") || - docAsString == QString::fromLatin1("<a>\n<b p:d=\"\" xmlns:p=\"NS\" p:c=\"\"/>\n</a>\n") || - docAsString == QString::fromLatin1("<a>\n<b xmlns:p=\"NS\" p:c=\"\" p:d=\"\"/>\n</a>\n") || - docAsString == QString::fromLatin1("<a>\n<b xmlns:p=\"NS\" p:d=\"\" p:c=\"\"/>\n</a>\n") - ); + QCOMPARE(docAsString, "<a>\n<b p:c=\"\" p:d=\"\" xmlns:p=\"NS\"/>\n</a>\n"); } void tst_QDom::setContentQXmlReaderOverload() const @@ -2232,6 +2228,31 @@ void tst_QDom::QTBUG49113_dontCrashWithNegativeIndex() const QVERIFY(node.isNull()); } +void tst_QDom::standalone() +{ + { + QDomDocument doc; + const QString dtd("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<Test/>\n"); + doc.setContent(dtd); + QVERIFY(doc.toString().contains("standalone=\'no\'")); + } + { + QDomDocument doc; + const QString dtd("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Test/>\n"); + doc.setContent(dtd); + QVERIFY(!doc.toString().contains("standalone")); + } + { + QDomDocument doc; + const QString dtd("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<Test/>\n"); + doc.setContent(dtd); + QVERIFY(doc.toString().contains("standalone=\'yes\'")); + } +} + void tst_QDom::DTDInternalSubset() const { QFETCH( QString, doc ); @@ -2296,5 +2317,19 @@ void tst_QDom::DTDInternalSubset_data() const << internalSubset0; } +void tst_QDom::splitTextLeakMemory() const +{ + QDomDocument doc; + QDomElement top = doc.createElement("top"); + QDomText text = doc.createTextNode("abcdefgh"); + top.appendChild(text); + QDomText end = text.splitText(2); + QCOMPARE(text.data(), "ab"_L1); + QCOMPARE(end.data(), "cdefgh"_L1); + // only the parent node and the document have a reference on the nodes + QCOMPARE(text.impl->ref.loadRelaxed(), 2); + QCOMPARE(end.impl->ref.loadRelaxed(), 2); +} + QTEST_MAIN(tst_QDom) #include "tst_qdom.moc" |