diff options
Diffstat (limited to 'tests/auto/qsvggenerator')
-rw-r--r-- | tests/auto/qsvggenerator/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/auto/qsvggenerator/qsvggenerator.pro | 8 | ||||
-rw-r--r-- | tests/auto/qsvggenerator/tst_qsvggenerator.cpp | 93 |
3 files changed, 68 insertions, 38 deletions
diff --git a/tests/auto/qsvggenerator/CMakeLists.txt b/tests/auto/qsvggenerator/CMakeLists.txt index 45b3ebe..bc07012 100644 --- a/tests/auto/qsvggenerator/CMakeLists.txt +++ b/tests/auto/qsvggenerator/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qsvggenerator.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qsvggenerator Test: @@ -7,7 +8,7 @@ qt_internal_add_test(tst_qsvggenerator SOURCES tst_qsvggenerator.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Svg diff --git a/tests/auto/qsvggenerator/qsvggenerator.pro b/tests/auto/qsvggenerator/qsvggenerator.pro deleted file mode 100644 index 1b6f329..0000000 --- a/tests/auto/qsvggenerator/qsvggenerator.pro +++ /dev/null @@ -1,8 +0,0 @@ -TARGET = tst_qsvggenerator -CONFIG += testcase -QT += svg xml testlib widgets gui-private - -SOURCES += tst_qsvggenerator.cpp - -RESOURCES += referenceSvgs/fileName_output.svg \ - referenceSvgs/radial_gradient.svg diff --git a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp index 4f626c3..d835e4b 100644 --- a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp +++ b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <QtTest/QtTest> @@ -50,6 +25,8 @@ public: private slots: void construction(); void fileName(); + void escapesTitle(); + void escapesDescription(); void outputDevice(); void sizeAndViewBox(); void metric(); @@ -144,6 +121,66 @@ void tst_QSvgGenerator::fileName() checkFile(fileName); } +void tst_QSvgGenerator::escapesTitle() +{ + QByteArray byteArray; + QBuffer buffer(&byteArray); + + const QString titleThatNeedsToBeEscaped("<malicious>\"title\" 'oh no'"); + + { + QSvgGenerator generator; + + generator.setOutputDevice(&buffer); + generator.setTitle(titleThatNeedsToBeEscaped); + + QPainter painter(&generator); + painter.end(); + } + + QDomDocument generated; + generated.setContent(byteArray); + + const auto titleElements = generated.documentElement().elementsByTagName("title"); + + QCOMPARE(1, titleElements.size()); + + const auto theOnlyTitleElement = titleElements.at(0); + + QCOMPARE(1, theOnlyTitleElement.childNodes().size()); + QCOMPARE(titleThatNeedsToBeEscaped, theOnlyTitleElement.firstChild().nodeValue()); +} + +void tst_QSvgGenerator::escapesDescription() +{ + QByteArray byteArray; + QBuffer buffer(&byteArray); + + const QString descriptionThatNeedsToBeEscaped("<evil>\"description\" 'whoopsie!'"); + + { + QSvgGenerator generator; + + generator.setOutputDevice(&buffer); + generator.setDescription(descriptionThatNeedsToBeEscaped); + + QPainter painter(&generator); + painter.end(); + } + + QDomDocument generated; + generated.setContent(byteArray); + + const auto descriptionElements = generated.documentElement().elementsByTagName("desc"); + + QCOMPARE(1, descriptionElements.size()); + + const auto theOnlyDescriptionElement = descriptionElements.at(0); + + QCOMPARE(1, theOnlyDescriptionElement.childNodes().size()); + QCOMPARE(descriptionThatNeedsToBeEscaped, theOnlyDescriptionElement.firstChild().nodeValue()); +} + void tst_QSvgGenerator::outputDevice() { QString fileName = "outputDevice_output.svg"; @@ -298,7 +335,7 @@ void tst_QSvgGenerator::fileEncoding() generator.setOutputDevice(&buffer); static const QChar unicode[] = { 'f', 'o', 'o', - 0x00F8, 'b', 'a', 'r'}; + u'\u00F8', 'b', 'a', 'r'}; int size = sizeof(unicode) / sizeof(QChar); QString unicodeString = QString::fromRawData(unicode, size); |