/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include "XMLWriter.h" #include "XMLWriterTest.h" #include "XMLWriterTest.moc" using namespace QPatternistSDK; QTEST_MAIN(XMLWriterTest) void XMLWriterTest::serialize() { QFETCH(QString, input); QFETCH(QString, expectedResult); QByteArray result; QBuffer returnBuffer(&result); XMLWriter writer(&returnBuffer); QXmlInputSource inputSource; inputSource.setData(input); QXmlSimpleReader reader; reader.setContentHandler(&writer); const bool parseSuccess = reader.parse(inputSource); Q_ASSERT_X(parseSuccess, Q_FUNC_INFO, "XMLWriter reported an error while serializing the input."); QCOMPARE(QString::fromLatin1(result), expectedResult); } void XMLWriterTest::serialize_data() { QTest::addColumn("input"); QTest::addColumn("expectedResult"); /* ------------------- Elements ------------------- */ QTest::newRow("Only an document element") << "" << "\n"; QTest::newRow("Document element containing a short closed element") << "" << "\n"; QTest::newRow("Complex nested elements") << "" << "\n"; /* ------------------------------------------------- */ /* ---------------- Element Content ---------------- */ QTest::newRow("Element content with simple content") << "content" << "\ncontent"; QTest::newRow("Element content with tricky to escape content") << ">>&'\"''/>" << "\n>>&'\"''/>"; /* ------------------------------------------------- */ /* ----------- Processing Instructions ------------- */ QTest::newRow("Simple processing instruction.") << "" << "\n"; /* ------------------------------------------------- */ /* --------------- 'xml' attributes ---------------- */ QTest::newRow("Simple xml:space attribute.") << "content" << "\ncontent"; QTest::newRow("Many 'xml' attributes.") << "content" << "\n" "content"; /* ------------------------------------------------- */ /* ------------ namespace declarations ------------- */ QTest::newRow("One simple namespace declaration.") << "" << "\n" ""; QTest::newRow("Two simple namespace declarations.") << "" << "\n" ""; QTest::newRow("A simple default namespace.") << "" << "\n" ""; /* ------------------------------------------------- */ /* -------- namespace declarations in use ---------- */ QTest::newRow("Simple use of a namespace declaration.") << "" << "\n" ""; /* ------------------------------------------------- */ } void XMLWriterTest::cdata() { /* QTest::newRow("Simple CDATA") << "" << "\n"; QTest::newRow("Complex CDATA") << ">&'\";&987;]]>" << "\n>&'\";&123;]]>"; */ } void XMLWriterTest::comments() { /* QTest::newRow("Simple comment") << "" << "\n"; QTest::newRow("Comment") << "" << "\n"; */ } void XMLWriterTest::doxygenExample() { #include "../docs/XMLWriterExample.cpp" /* When changing, remember to update the Doxygen in XMLWriter.h */ const QByteArray expectedResult( "\n" "\n" "

Hello World!

" ); QCOMPARE(QString::fromLatin1(result), QString::fromLatin1(expectedResult)); } // vim: et:ts=4:sw=4:sts=4