diff options
Diffstat (limited to 'tests/auto/xml')
-rw-r--r-- | tests/auto/xml/dom/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/xml/dom/qdom/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/xml/dom/qdom/tst_qdom.cpp | 53 |
3 files changed, 51 insertions, 13 deletions
diff --git a/tests/auto/xml/dom/CMakeLists.txt b/tests/auto/xml/dom/CMakeLists.txt index bb67fb5f2a..daa837c2cf 100644 --- a/tests/auto/xml/dom/CMakeLists.txt +++ b/tests/auto/xml/dom/CMakeLists.txt @@ -1,6 +1,4 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from dom.pro. - add_subdirectory(qdom) diff --git a/tests/auto/xml/dom/qdom/CMakeLists.txt b/tests/auto/xml/dom/qdom/CMakeLists.txt index 18f6bab437..4eea988cc3 100644 --- a/tests/auto/xml/dom/qdom/CMakeLists.txt +++ b/tests/auto/xml/dom/qdom/CMakeLists.txt @@ -1,12 +1,16 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qdom.pro. - ##################################################################### ## tst_qdom Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdom LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -20,5 +24,6 @@ qt_internal_add_test(tst_qdom tst_qdom.cpp LIBRARIES Qt::Xml + Qt::XmlPrivate TESTDATA ${test_data} ) diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index 9ea09215a8..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; @@ -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" |