diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/painting/painting.pro | 3 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagelayout/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagelayout/qpagelayout.pro | 9 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp | 277 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagesize/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagesize/qpagesize.pro | 9 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp | 258 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpdfwriter/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpdfwriter/qpdfwriter.pro | 9 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp | 265 |
10 files changed, 833 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/painting.pro b/tests/auto/gui/painting/painting.pro index 8f018fd921..0f7595c871 100644 --- a/tests/auto/gui/painting/painting.pro +++ b/tests/auto/gui/painting/painting.pro @@ -5,8 +5,11 @@ SUBDIRS=\ qcolor \ qbrush \ qregion \ + qpagelayout \ + qpagesize \ qpainter \ qpathclipper \ + qpdfwriter \ qpen \ qpaintengine \ qtransform \ diff --git a/tests/auto/gui/painting/qpagelayout/.gitignore b/tests/auto/gui/painting/qpagelayout/.gitignore new file mode 100644 index 0000000000..7c7dcd262b --- /dev/null +++ b/tests/auto/gui/painting/qpagelayout/.gitignore @@ -0,0 +1 @@ +tst_qpagelayout diff --git a/tests/auto/gui/painting/qpagelayout/qpagelayout.pro b/tests/auto/gui/painting/qpagelayout/qpagelayout.pro new file mode 100644 index 0000000000..38a1064357 --- /dev/null +++ b/tests/auto/gui/painting/qpagelayout/qpagelayout.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qpagelayout +SOURCES += tst_qpagelayout.cpp + +QT += gui-private testlib + +DEFINES += QT_USE_USING_NAMESPACE +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp new file mode 100644 index 0000000000..30d25f00d2 --- /dev/null +++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2014 John Layt <jlayt@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtGui/qpagelayout.h> + +class tst_QPageLayout : public QObject +{ + Q_OBJECT + +private slots: + void invalid(); + void basics(); + void setGetMargins(); +}; + +void tst_QPageLayout::invalid() +{ + // Invalid + QPageLayout invalid = QPageLayout(); + QCOMPARE(invalid.isValid(), false); + invalid = QPageLayout(QPageSize(), QPageLayout::Portrait, QMarginsF()); + QCOMPARE(invalid.isValid(), false); +} + +void tst_QPageLayout::basics() +{ + // Simple A4, no margins + QPageLayout simple = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.isValid(), true); + QCOMPARE(simple.pageSize().id(), QPageSize::A4); + QCOMPARE(simple.orientation(), QPageLayout::Portrait); + QCOMPARE(simple.margins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.margins(QPageLayout::Millimeter), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.marginsPoints(), QMargins(0, 0, 0, 0)); + QCOMPARE(simple.marginsPixels(72), QMargins(0, 0, 0, 0)); + QCOMPARE(simple.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.maximumMargins(), QMarginsF(595, 842, 595, 842)); + QCOMPARE(simple.fullRect(), QRectF(0, 0, 595, 842)); + QCOMPARE(simple.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297)); + QCOMPARE(simple.fullRectPoints(), QRect(0, 0, 595, 842)); + QCOMPARE(simple.fullRectPixels(72), QRect(0, 0, 595, 842)); + QCOMPARE(simple.paintRect(), QRectF(0, 0, 595, 842)); + QCOMPARE(simple.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297)); + QCOMPARE(simple.paintRectPoints(), QRect(0, 0, 595, 842)); + QCOMPARE(simple.paintRectPixels(72), QRect(0, 0, 595, 842)); + + // Change orientation + simple.setOrientation(QPageLayout::Landscape); + QCOMPARE(simple.orientation(), QPageLayout::Landscape); + QCOMPARE(simple.margins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(simple.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(simple.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(simple.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(simple.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(simple.paintRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(simple.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(simple.paintRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(simple.paintRectPixels(72), QRect(0, 0, 842, 595)); + + // Change mode + QCOMPARE(simple.mode(), QPageLayout::StandardMode); + simple.setMode(QPageLayout::FullPageMode); + QCOMPARE(simple.mode(), QPageLayout::FullPageMode); + QCOMPARE(simple.orientation(), QPageLayout::Landscape); + QCOMPARE(simple.margins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(simple.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(simple.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(simple.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(simple.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(simple.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(simple.paintRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(simple.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(simple.paintRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(simple.paintRectPixels(72), QRect(0, 0, 842, 595)); + + // A4, 10pt margins + QPageLayout tenpoint = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(10, 10, 10, 10)); + QCOMPARE(tenpoint.isValid(), true); + QCOMPARE(tenpoint.margins(), QMarginsF(10, 10, 10, 10)); + QCOMPARE(tenpoint.margins(QPageLayout::Millimeter), QMarginsF(3.53, 3.53, 3.53, 3.53)); + QCOMPARE(tenpoint.marginsPoints(), QMargins(10, 10, 10, 10)); + QCOMPARE(tenpoint.marginsPixels(72), QMargins(10, 10, 10, 10)); + QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(tenpoint.maximumMargins(), QMarginsF(595, 842, 595, 842)); + QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 595, 842)); + QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297)); + QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 595, 842)); + QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 595, 842)); + QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 575, 822)); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 202.94, 289.94)); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).x(), 3.53); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).y(), 3.53); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).width(), 202.94); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).height(), 289.94); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).left(), 3.53); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).right(), 206.47); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).top(), 3.53); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).bottom(), 293.47); + QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 575, 822)); + QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 575, 822)); + + // Change orientation + tenpoint.setOrientation(QPageLayout::Landscape); + QCOMPARE(tenpoint.orientation(), QPageLayout::Landscape); + QCOMPARE(tenpoint.margins(), QMarginsF(10, 10, 10, 10)); + QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(tenpoint.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 822, 575)); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 289.94, 202.94)); + QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 822, 575)); + QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 822, 575)); + + // Change mode + QCOMPARE(tenpoint.mode(), QPageLayout::StandardMode); + tenpoint.setMode(QPageLayout::FullPageMode); + QCOMPARE(tenpoint.mode(), QPageLayout::FullPageMode); + QCOMPARE(tenpoint.orientation(), QPageLayout::Landscape); + QCOMPARE(tenpoint.margins(), QMarginsF(10, 10, 10, 10)); + QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(tenpoint.maximumMargins(), QMarginsF(842, 595, 842, 595)); + QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.paintRect(), QRectF(0, 0, 842, 595)); + QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(tenpoint.paintRectPoints(), QRect(0, 0, 842, 595)); + QCOMPARE(tenpoint.paintRectPixels(72), QRect(0, 0, 842, 595)); +} + +void tst_QPageLayout::setGetMargins() +{ + // A4, 20pt margins + QMarginsF margins = QMarginsF(10, 10, 10, 10); + QMarginsF min = QMarginsF(10, 10, 10, 10); + QMarginsF max = QMarginsF(585, 832, 585, 832); + QPageLayout change = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min); + QCOMPARE(change.isValid(), true); + QCOMPARE(change.margins(), margins); + QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(3.53, 3.53, 3.53, 3.53)); + QCOMPARE(change.marginsPoints(), QMargins(10, 10, 10, 10)); + QCOMPARE(change.marginsPixels(72), QMargins(10, 10, 10, 10)); + QCOMPARE(change.minimumMargins(), min); + QCOMPARE(change.maximumMargins(), max); + + // Set magins within min/max ok + margins = QMarginsF(20, 20, 20, 20); + change.setMargins(margins); + QCOMPARE(change.margins(QPageLayout::Millimeter), QMarginsF(7.06, 7.06, 7.06, 7.06)); + QCOMPARE(change.marginsPoints(), QMargins(20, 20, 20, 20)); + QCOMPARE(change.marginsPixels(72), QMargins(20, 20, 20, 20)); + QCOMPARE(change.margins(), margins); + + // Set margins all below min is rejected + change.setMargins(QMarginsF(0, 0, 0, 0)); + QCOMPARE(change.margins(), margins); + + // Set margins all above max is rejected + change.setMargins(QMarginsF(1000, 1000, 1000, 1000)); + QCOMPARE(change.margins(), margins); + + // Only 1 wrong, set still rejects + change.setMargins(QMarginsF(50, 50, 50, 0)); + QCOMPARE(change.margins(), margins); + + // Set page size resets min/max, clamps existing margins + change.setMargins(change.maximumMargins()); + change.setPageSize(QPageSize(QPageSize::A5)); + QCOMPARE(change.margins(), QMarginsF(420, 595, 420, 595)); + QCOMPARE(change.minimumMargins(), QMarginsF(0, 0, 0, 0)); + QCOMPARE(change.maximumMargins(), QMarginsF(420, 595, 420, 595)); + + // Set page size, sets min/max, clamps existing margins + margins = QMarginsF(20, 500, 20, 500); + change.setMargins(margins); + QCOMPARE(change.margins(), margins); + min = QMarginsF(30, 30, 30, 30); + max = QMarginsF(267, 390, 267, 390); + change.setPageSize(QPageSize(QPageSize::A6)); + change.setMinimumMargins(min); + QCOMPARE(change.margins(), QMarginsF(30, 390, 30, 390)); + QCOMPARE(change.minimumMargins(), min); + QCOMPARE(change.maximumMargins(), max); + + // A4, 20pt margins + margins = QMarginsF(20, 20, 20, 20); + min = QMarginsF(10, 10, 10, 10); + max = QMarginsF(585, 832, 585, 832); + QPageLayout fullPage = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, margins, QPageLayout::Point, min); + fullPage.setMode(QPageLayout::FullPageMode); + QCOMPARE(fullPage.isValid(), true); + QCOMPARE(fullPage.margins(), margins); + QCOMPARE(fullPage.minimumMargins(), min); + QCOMPARE(fullPage.maximumMargins(), max); + + // Set margins within min/max ok + margins = QMarginsF(50, 50, 50, 50); + fullPage.setMargins(margins); + QCOMPARE(fullPage.margins(), margins); + + // Set margins all below min is accepted + margins = QMarginsF(0, 0, 0, 0); + fullPage.setMargins(margins); + QCOMPARE(fullPage.margins(), margins); + + // Set margins all above max is rejected + margins = QMarginsF(1000, 1000, 1000, 1000); + fullPage.setMargins(margins); + QCOMPARE(fullPage.margins(), margins); + + // Only 1 wrong, set still accepts + margins = QMarginsF(50, 50, 50, 0); + fullPage.setMargins(margins); + QCOMPARE(fullPage.margins(), margins); + + // Set page size, sets min/max, clamps existing margins + margins = QMarginsF(20, 500, 20, 500); + fullPage.setMargins(margins); + QCOMPARE(fullPage.margins(), margins); + min = QMarginsF(30, 30, 30, 30); + max = QMarginsF(267, 390, 267, 390); + fullPage.setPageSize(QPageSize(QPageSize::A6)); + fullPage.setMinimumMargins(min); + QCOMPARE(fullPage.margins(), margins); + QCOMPARE(fullPage.minimumMargins(), min); + QCOMPARE(fullPage.maximumMargins(), max); +} + +QTEST_APPLESS_MAIN(tst_QPageLayout) + +#include "tst_qpagelayout.moc" diff --git a/tests/auto/gui/painting/qpagesize/.gitignore b/tests/auto/gui/painting/qpagesize/.gitignore new file mode 100644 index 0000000000..773a466f6d --- /dev/null +++ b/tests/auto/gui/painting/qpagesize/.gitignore @@ -0,0 +1 @@ +tst_qpagesize diff --git a/tests/auto/gui/painting/qpagesize/qpagesize.pro b/tests/auto/gui/painting/qpagesize/qpagesize.pro new file mode 100644 index 0000000000..5836dc9ba0 --- /dev/null +++ b/tests/auto/gui/painting/qpagesize/qpagesize.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qpagesize +SOURCES += tst_qpagesize.cpp + +QT += testlib + +DEFINES += QT_USE_USING_NAMESPACE +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp new file mode 100644 index 0000000000..968c5ff617 --- /dev/null +++ b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp @@ -0,0 +1,258 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtGlobal> +#include <QtAlgorithms> +#include <QtGui/QPageSize> + +#ifdef Q_OS_WIN +#include <QtCore/qt_windows.h> +#endif // Q_OS_WIN + +class tst_QPageSize : public QObject +{ + Q_OBJECT + +private slots: + void basics(); + void fuzzy(); + void custom(); + void statics(); +}; + +void tst_QPageSize::basics() +{ + // Invalid + QPageSize invalid = QPageSize(QPageSize::Custom); + QCOMPARE(invalid.isValid(), false); + invalid = QPageSize(QSize()); + QCOMPARE(invalid.isValid(), false); + invalid = QPageSize(QSizeF(), QPageSize::Millimeter); + QCOMPARE(invalid.isValid(), false); + + // Simple QPageSize::PaperSizeId + QPageSize a4 = QPageSize(QPageSize::A4); + QCOMPARE(a4.isValid(), true); + QCOMPARE(a4.key(), QString("A4")); + QCOMPARE(a4.name(), QString("A4")); + QCOMPARE(a4.id(), QPageSize::A4); +#ifdef Q_OS_WIN + QCOMPARE(a4.windowsId(), DMPAPER_A4); +#else + QCOMPARE(a4.windowsId(), 9); // DMPAPER_A4 +#endif + QCOMPARE(a4.definitionSize(), QSizeF(210, 297)); + QCOMPARE(a4.definitionUnits(), QPageSize::Millimeter); + QCOMPARE(a4.size(QPageSize::Millimeter), QSizeF(210, 297)); + QCOMPARE(a4.size(QPageSize::Inch), QSizeF(8.27, 11.69)); + QCOMPARE(a4.size(QPageSize::Pica), QSizeF(49.58, 70.17)); + QCOMPARE(a4.sizePoints(), QSize(595, 842)); + QCOMPARE(a4.sizePixels(72), QSize(595, 842)); + QCOMPARE(a4.rect(QPageSize::Millimeter), QRectF(0, 0, 210, 297)); + QCOMPARE(a4.rect(QPageSize::Inch), QRectF(0, 0, 8.27, 11.69)); + QCOMPARE(a4.rect(QPageSize::Pica), QRectF(0, 0, 49.58, 70.17)); + QCOMPARE(a4.rectPoints(), QRect(0, 0, 595, 842)); + QCOMPARE(a4.rectPixels(72), QRect(0, 0, 595, 842)); + + // Simple QPageSize::PaperSizeId later in list + QPageSize folio = QPageSize(QPageSize::Folio); + QCOMPARE(folio.isValid(), true); + QCOMPARE(folio.key(), QString("Folio")); + QCOMPARE(folio.name(), QString("Folio (8.27 x 13 in)")); + QCOMPARE(folio.id(), QPageSize::Folio); + QCOMPARE(folio.definitionSize(), QSizeF(210, 330)); + QCOMPARE(folio.definitionUnits(), QPageSize::Millimeter); + QCOMPARE(folio.size(QPageSize::Millimeter), QSizeF(210, 330)); + QCOMPARE(folio.sizePoints(), QSize(595, 935)); + QCOMPARE(folio.sizePixels(72), QSize(595, 935)); + QCOMPARE(folio.size(QPageSize::Inch), QSizeF(8.27, 13)); + + // Simple QPageSize::PaperSizeId last in list + QPageSize you4 = QPageSize(QPageSize::EnvelopeYou4); + QCOMPARE(you4.isValid(), true); + QCOMPARE(you4.key(), QString("EnvYou4")); + QCOMPARE(you4.name(), QString("Envelope You 4")); + QCOMPARE(you4.id(), QPageSize::EnvelopeYou4); +#ifdef Q_OS_WIN + QCOMPARE(you4.windowsId(), DMPAPER_JENV_YOU4); +#else + QCOMPARE(you4.windowsId(), 91); +#endif + QCOMPARE(you4.size(QPageSize::Millimeter), QSizeF(105, 235)); + QCOMPARE(you4.size(QPageSize::Inch), QSizeF(4.13, 9.25)); + QCOMPARE(you4.sizePoints(), QSize(298, 666)); + QCOMPARE(you4.sizePixels(72), QSize(298, 666)); + + // Simple QSize in Points + QPageSize a4b = QPageSize(QSize(595, 842)); + QCOMPARE(a4b.isValid(), true); + QCOMPARE(a4b.id(), QPageSize::A4); + QCOMPARE(a4b.sizePoints(), QSize(595, 842)); + + // Simple QSize in Points later in list, custom name + QPageSize folio2 = QPageSize(QSize(595, 935), QStringLiteral("Folio2")); + QCOMPARE(folio2.isValid(), true); + QCOMPARE(folio2.name(), QString("Folio2")); + QCOMPARE(folio2.id(), QPageSize::Folio); + QCOMPARE(folio2.sizePoints(), QSize(595, 935)); + + // Comparisons + QCOMPARE((a4 == folio), false); + QCOMPARE((a4.isEquivalentTo(folio)), false); + QCOMPARE((a4 == a4b), true); + QCOMPARE((a4.isEquivalentTo(a4b)), true); + QCOMPARE((folio == folio2), false); // Name different + QCOMPARE((folio.isEquivalentTo(folio2)), true); + + // Simple QSize in Millimeters + QPageSize folio3 = QPageSize(QSizeF(210, 330), QPageSize::Millimeter); + QCOMPARE(folio3.isValid(), true); + QCOMPARE(folio3.id(), QPageSize::Folio); + QCOMPARE(folio3.sizePoints(), QSize(595, 935)); +} + +void tst_QPageSize::fuzzy() +{ + // Using FuzzyMatch by default + + // Simple QSize within 3 Points + QPageSize a4a = QPageSize(QSize(592, 845)); + QCOMPARE(a4a.isValid(), true); + QCOMPARE(a4a.id(), QPageSize::A4); + QCOMPARE(a4a.sizePoints(), QSize(595, 842)); + + // Simple QSizeF within 1mm + QPageSize a4b = QPageSize(QSizeF(211, 298), QPageSize::Millimeter); + QCOMPARE(a4b.isValid(), true); + QCOMPARE(a4b.id(), QPageSize::A4); + QCOMPARE(a4b.size(QPageSize::Millimeter), QSizeF(210, 297)); + QCOMPARE(a4b.sizePoints(), QSize(595, 842)); + + // Using FuzzyOrientationMatch + + // Exact A4 in landscape mode + QPageSize a4l = QPageSize(QSize(842, 595)); + QCOMPARE(a4l.isValid(), true); + QCOMPARE(a4l.id(), QPageSize::Custom); + QCOMPARE(a4l.sizePoints(), QSize(842, 595)); + + a4l = QPageSize(QSize(842, 595), QString(), QPageSize::FuzzyOrientationMatch); + QCOMPARE(a4l.isValid(), true); + QCOMPARE(a4l.id(), QPageSize::A4); + QCOMPARE(a4l.sizePoints(), QSize(595, 842)); + + // Using ExactMatch + + // Simple QSize within 3 Points + QPageSize a4d = QPageSize(QSize(592, 845), QString(), QPageSize::ExactMatch); + QCOMPARE(a4d.isValid(), true); + QCOMPARE(a4d.id(), QPageSize::Custom); + QCOMPARE(a4d.sizePoints(), QSize(592, 845)); + + // Simple QSizeF within 1mm + QPageSize a4e = QPageSize(QSizeF(211, 298), QPageSize::Millimeter, QString(), QPageSize::ExactMatch); + QCOMPARE(a4e.isValid(), true); + QCOMPARE(a4e.id(), QPageSize::Custom); + QCOMPARE(a4e.size(QPageSize::Millimeter), QSizeF(211, 298)); + QCOMPARE(a4e.sizePoints(), QSize(598, 845)); +} + +void tst_QPageSize::custom() +{ + // Simple non-standard Points QSize + QPageSize custom1 = QPageSize(QSize(500, 600)); + QCOMPARE(custom1.isValid(), true); + QCOMPARE(custom1.key(), QString("Custom.500x600")); + QCOMPARE(custom1.name(), QString("Custom (500pt x 600pt)")); + QCOMPARE(custom1.id(), QPageSize::Custom); + QCOMPARE(custom1.definitionSize(), QSizeF(500, 600)); + QCOMPARE(custom1.definitionUnits(), QPageSize::Point); + QCOMPARE(custom1.size(QPageSize::Millimeter), QSizeF(176.39, 211.67)); + QCOMPARE(custom1.size(QPageSize::Pica), QSizeF(41.67, 50)); + QCOMPARE(custom1.sizePoints(), QSize(500, 600)); + QCOMPARE(custom1.sizePixels(72), QSize(500, 600)); + + // Simple non-standard MM QSizeF + QPageSize custom2 = QPageSize(QSizeF(500.3, 600.57), QPageSize::Millimeter); + QCOMPARE(custom2.isValid(), true); + QCOMPARE(custom2.key(), QString("Custom.500.3x600.57mm")); + QCOMPARE(custom2.name(), QString("Custom (500.3mm x 600.57mm)")); + QCOMPARE(custom2.id(), QPageSize::Custom); + QCOMPARE(custom2.definitionSize(), QSizeF(500.3, 600.57)); + QCOMPARE(custom2.definitionUnits(), QPageSize::Millimeter); + QCOMPARE(custom2.size(QPageSize::Millimeter), QSizeF(500.3, 600.57)); + QCOMPARE(custom2.size(QPageSize::Pica), QSizeF(118.18, 141.87)); + QCOMPARE(custom2.sizePoints(), QSize(1418, 1702)); + QCOMPARE(custom2.sizePixels(72), QSize(1418, 1702)); +} + +void tst_QPageSize::statics() +{ + QCOMPARE(QPageSize::key(QPageSize::EnvelopeYou4), QString("EnvYou4")); + QCOMPARE(QPageSize::name(QPageSize::EnvelopeYou4), QString("Envelope You 4")); + +#ifdef Q_OS_WIN + QCOMPARE(QPageSize::windowsId(QPageSize::EnvelopeYou4), DMPAPER_JENV_YOU4); + QCOMPARE(QPageSize::id(DMPAPER_JENV_YOU4), QPageSize::EnvelopeYou4); + QCOMPARE(QPageSize::id(DMPAPER_A4_ROTATED), QPageSize::A4); +#else + QCOMPARE(QPageSize::windowsId(QPageSize::EnvelopeYou4), 91); + QCOMPARE(QPageSize::id(91), QPageSize::EnvelopeYou4); + QCOMPARE(QPageSize::id(77), QPageSize::A4); +#endif + + QCOMPARE(QPageSize::id(QSize(298, 666)), QPageSize::EnvelopeYou4); + QCOMPARE(QPageSize::id(QSizeF(105, 235), QPageSize::Millimeter), QPageSize::EnvelopeYou4); + + QCOMPARE(QPageSize::definitionSize(QPageSize::Letter), QSizeF(8.5, 11)); + QCOMPARE(QPageSize::definitionUnits(QPageSize::Letter), QPageSize::Inch); + QCOMPARE(QPageSize::definitionSize(QPageSize::EnvelopeYou4), QSizeF(105, 235)); + QCOMPARE(QPageSize::definitionUnits(QPageSize::EnvelopeYou4), QPageSize::Millimeter); + + QCOMPARE(QPageSize::size(QPageSize::EnvelopeYou4, QPageSize::Millimeter), QSizeF(105, 235)); + QCOMPARE(QPageSize::sizePoints(QPageSize::EnvelopeYou4), QSize(298, 666)); + QCOMPARE(QPageSize::sizePixels(QPageSize::EnvelopeYou4, 72), QSize(298, 666)); +} + +QTEST_APPLESS_MAIN(tst_QPageSize) + +#include "tst_qpagesize.moc" diff --git a/tests/auto/gui/painting/qpdfwriter/.gitignore b/tests/auto/gui/painting/qpdfwriter/.gitignore new file mode 100644 index 0000000000..5307a5ed2a --- /dev/null +++ b/tests/auto/gui/painting/qpdfwriter/.gitignore @@ -0,0 +1 @@ +tst_qpdfwriter diff --git a/tests/auto/gui/painting/qpdfwriter/qpdfwriter.pro b/tests/auto/gui/painting/qpdfwriter/qpdfwriter.pro new file mode 100644 index 0000000000..fda0fad3b5 --- /dev/null +++ b/tests/auto/gui/painting/qpdfwriter/qpdfwriter.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qpdfwriter +SOURCES += tst_qpdfwriter.cpp + +QT += gui-private testlib + +DEFINES += QT_USE_USING_NAMESPACE +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp new file mode 100644 index 0000000000..f06351b7b7 --- /dev/null +++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp @@ -0,0 +1,265 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtGlobal> +#include <QtAlgorithms> +#include <QtGui/QPageLayout> +#include <QtGui/QPdfWriter> + +class tst_QPdfWriter : public QObject +{ + Q_OBJECT + +private slots: + void basics(); + void testPageMetrics_data(); + void testPageMetrics(); +}; + +void tst_QPdfWriter::basics() +{ + QTemporaryFile file; + if (!file.open()) + QSKIP("Couldn't open temp file!"); + QPdfWriter writer(file.fileName()); + + QCOMPARE(writer.title(), QString()); + writer.setTitle(QString("Test Title")); + QCOMPARE(writer.title(), QString("Test Title")); + + QCOMPARE(writer.creator(), QString()); + writer.setCreator(QString("Test Creator")); + QCOMPARE(writer.creator(), QString("Test Creator")); + + QCOMPARE(writer.resolution(), 1200); + writer.setResolution(600); + QCOMPARE(writer.resolution(), 600); + + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4); + QCOMPARE(writer.pageSize(), QPdfWriter::A4); + QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297)); + + writer.setPageSize(QPageSize(QPageSize::A5)); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A5); + QCOMPARE(writer.pageSize(), QPdfWriter::A5); + QCOMPARE(writer.pageSizeMM(), QSizeF(148, 210)); + + writer.setPageSize(QPdfWriter::A3); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3); + QCOMPARE(writer.pageSize(), QPdfWriter::A3); + QCOMPARE(writer.pageSizeMM(), QSizeF(297, 420)); + + writer.setPageSizeMM(QSize(210, 297)); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4); + QCOMPARE(writer.pageSize(), QPdfWriter::A4); + QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297)); + + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait); + writer.setPageOrientation(QPageLayout::Landscape); + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape); + QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297)); + + QCOMPARE(writer.pageLayout().margins(), QMarginsF(10, 10, 10, 10)); + QCOMPARE(writer.pageLayout().units(), QPageLayout::Point); + QCOMPARE(writer.margins().left, 3.53); // mm + QCOMPARE(writer.margins().right, 3.53); + QCOMPARE(writer.margins().top, 3.53); + QCOMPARE(writer.margins().bottom, 3.53); + writer.setPageMargins(QMarginsF(20, 20, 20, 20), QPageLayout::Millimeter); + QCOMPARE(writer.pageLayout().margins(), QMarginsF(20, 20, 20, 20)); + QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter); + QCOMPARE(writer.margins().left, 20.0); + QCOMPARE(writer.margins().right, 20.0); + QCOMPARE(writer.margins().top, 20.0); + QCOMPARE(writer.margins().bottom, 20.0); + QPdfWriter::Margins margins = {50, 50, 50, 50}; + writer.setMargins(margins); + QCOMPARE(writer.pageLayout().margins(), QMarginsF(50, 50, 50, 50)); + QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter); + QCOMPARE(writer.margins().left, 50.0); + QCOMPARE(writer.margins().right, 50.0); + QCOMPARE(writer.margins().top, 50.0); + QCOMPARE(writer.margins().bottom, 50.0); + + QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210)); + QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(50, 50, 197, 110)); +} + +// Test the old page metrics methods, see also QPrinter tests for the same. +void tst_QPdfWriter::testPageMetrics_data() +{ + QTest::addColumn<int>("pageSize"); + QTest::addColumn<qreal>("widthMMf"); + QTest::addColumn<qreal>("heightMMf"); + QTest::addColumn<bool>("setMargins"); + QTest::addColumn<qreal>("leftMMf"); + QTest::addColumn<qreal>("rightMMf"); + QTest::addColumn<qreal>("topMMf"); + QTest::addColumn<qreal>("bottomMMf"); + + QTest::newRow("A4") << int(QPdfWriter::A4) << 210.0 << 297.0 << false << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("A4 Margins") << int(QPdfWriter::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0; + QTest::newRow("Portrait") << -1 << 345.0 << 678.0 << false << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("Portrait Margins") << -1 << 345.0 << 678.0 << true << 20.0 << 30.0 << 40.0 << 50.0; + QTest::newRow("Landscape") << -1 << 678.0 << 345.0 << false << 3.53 << 3.53 << 3.53 << 3.53; + QTest::newRow("Landscape Margins") << -1 << 678.0 << 345.0 << true << 20.0 << 30.0 << 40.0 << 50.0; +} + +void tst_QPdfWriter::testPageMetrics() +{ + QFETCH(int, pageSize); + QFETCH(qreal, widthMMf); + QFETCH(qreal, heightMMf); + QFETCH(bool, setMargins); + QFETCH(qreal, leftMMf); + QFETCH(qreal, rightMMf); + QFETCH(qreal, topMMf); + QFETCH(qreal, bottomMMf); + + QSizeF sizeMMf = QSizeF(widthMMf, heightMMf); + + QTemporaryFile file; + if (!file.open()) + QSKIP("Couldn't open temp file!"); + QPdfWriter writer(file.fileName()); + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait); + + if (setMargins) { + // Setup the given margins + QPdfWriter::Margins margins; + margins.left = leftMMf; + margins.right = rightMMf; + margins.top = topMMf; + margins.bottom = bottomMMf; + writer.setMargins(margins); + QCOMPARE(writer.margins().left, leftMMf); + QCOMPARE(writer.margins().right, rightMMf); + QCOMPARE(writer.margins().top, topMMf); + QCOMPARE(writer.margins().bottom, bottomMMf); + } + + + // Set the given size, in Portrait mode + if (pageSize < 0) { + writer.setPageSizeMM(sizeMMf); + QCOMPARE(writer.pageSize(), QPdfWriter::Custom); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); + } else { + writer.setPageSize(QPdfWriter::PageSize(pageSize)); + QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); + } + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait); + QCOMPARE(writer.margins().left, leftMMf); + QCOMPARE(writer.margins().right, rightMMf); + QCOMPARE(writer.margins().top, topMMf); + QCOMPARE(writer.margins().bottom, bottomMMf); + + // QPagedPaintDevice::pageSizeMM() always returns Portrait + QCOMPARE(writer.pageSizeMM(), sizeMMf); + + // QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation + QCOMPARE(writer.widthMM(), qRound(widthMMf - leftMMf - rightMMf)); + QCOMPARE(writer.heightMM(), qRound(heightMMf - topMMf - bottomMMf)); + + // Now switch to Landscape mode, size should be unchanged, but rect and metrics should change + writer.setPageOrientation(QPageLayout::Landscape); + if (pageSize < 0) { + QCOMPARE(writer.pageSize(), QPdfWriter::Custom); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); + } else { + QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); + } + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape); + QCOMPARE(writer.margins().left, leftMMf); + QCOMPARE(writer.margins().right, rightMMf); + QCOMPARE(writer.margins().top, topMMf); + QCOMPARE(writer.margins().bottom, bottomMMf); + + // QPagedPaintDevice::pageSizeMM() always returns Portrait + QCOMPARE(writer.pageSizeMM(), sizeMMf); + + // QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation + QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf)); + QCOMPARE(writer.heightMM(), qRound(widthMMf - topMMf - bottomMMf)); + + // QPdfWriter::fullRect() always returns set orientation + QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, heightMMf, widthMMf)); + + // QPdfWriter::paintRect() always returns set orientation + QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(leftMMf, topMMf, heightMMf - leftMMf - rightMMf, widthMMf - topMMf - bottomMMf)); + + + // Now while in Landscape mode, set the size again, results should be the same + if (pageSize < 0) { + writer.setPageSizeMM(sizeMMf); + QCOMPARE(writer.pageSize(), QPdfWriter::Custom); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::Custom); + } else { + writer.setPageSize(QPdfWriter::PageSize(pageSize)); + QCOMPARE(writer.pageSize(), QPdfWriter::PageSize(pageSize)); + QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize)); + } + QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape); + QCOMPARE(writer.margins().left, leftMMf); + QCOMPARE(writer.margins().right, rightMMf); + QCOMPARE(writer.margins().top, topMMf); + QCOMPARE(writer.margins().bottom, bottomMMf); + + // QPagedPaintDevice::pageSizeMM() always returns Portrait + QCOMPARE(writer.pageSizeMM(), sizeMMf); + + // QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation + QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf)); + QCOMPARE(writer.heightMM(), qRound(widthMMf - topMMf - bottomMMf)); + + // QPdfWriter::fullRect() always returns set orientation + QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, heightMMf, widthMMf)); + + // QPdfWriter::paintRect() always returns set orientation + QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(leftMMf, topMMf, heightMMf - leftMMf - rightMMf, widthMMf - topMMf - bottomMMf)); +} + +QTEST_MAIN(tst_QPdfWriter) + +#include "tst_qpdfwriter.moc" |