summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp')
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp126
1 files changed, 51 insertions, 75 deletions
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index 3fbe16575d..4d6b1f01b9 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** 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 <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QtGlobal>
#include <QtAlgorithms>
+#include <QTemporaryFile>
+
#include <QtGui/QAbstractTextDocumentLayout>
#include <QtGui/QPageLayout>
#include <QtGui/QPdfWriter>
@@ -65,50 +42,49 @@ void tst_QPdfWriter::basics()
QCOMPARE(writer.resolution(), 600);
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
- QCOMPARE(writer.pageSize(), QPdfWriter::A4);
- QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), 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));
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(148, 210));
writer.setPageSize(QPageSize(QPageSize::A3));
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
- QCOMPARE(writer.pageSize(), QPdfWriter::A3);
- QCOMPARE(writer.pageSizeMM(), QSizeF(297, 420));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(297, 420));
writer.setPageSize(QPageSize(QSize(210, 297), QPageSize::Millimeter));
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
- QCOMPARE(writer.pageSize(), QPdfWriter::A4);
- QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), 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().pageSize().size(QPageSize::Millimeter), 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);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), 3.53); // mm
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), 3.53);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), 3.53);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).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);
+ QCOMPARE(writer.pageLayout().margins().left(), 20.0);
+ QCOMPARE(writer.pageLayout().margins().right(), 20.0);
+ QCOMPARE(writer.pageLayout().margins().top(), 20.0);
+ QCOMPARE(writer.pageLayout().margins().bottom(), 20.0);
const QMarginsF margins = {50, 50, 50, 50};
writer.setPageMargins(margins, QPageLayout::Millimeter);
QCOMPARE(writer.pageLayout().margins(), margins);
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().margins().left(), 50.0);
+ QCOMPARE(writer.pageLayout().margins().right(), 50.0);
+ QCOMPARE(writer.pageLayout().margins().top(), 50.0);
+ QCOMPARE(writer.pageLayout().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));
@@ -185,10 +161,10 @@ void tst_QPdfWriter::testPageMetrics()
if (setMargins) {
// Setup the given margins
writer.setPageMargins({leftMMf, topMMf, rightMMf, bottomMMf}, QPageLayout::Millimeter);
- QCOMPARE(writer.margins().left, leftMMf);
- QCOMPARE(writer.margins().right, rightMMf);
- QCOMPARE(writer.margins().top, topMMf);
- QCOMPARE(writer.margins().bottom, bottomMMf);
+ QCOMPARE(writer.pageLayout().margins().left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins().right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins().top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins().bottom(), bottomMMf);
}
// Set the given size, in Portrait mode
@@ -196,16 +172,16 @@ void tst_QPdfWriter::testPageMetrics()
? QPageSize(sizeMMf, QPageSize::Millimeter) : QPageSize(pageSizeId);
writer.setPageSize(pageSize);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
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);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(widthMMf - leftMMf - rightMMf));
@@ -214,15 +190,15 @@ void tst_QPdfWriter::testPageMetrics()
// Now switch to Landscape mode, size should be unchanged, but rect and metrics should change
writer.setPageOrientation(QPageLayout::Landscape);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
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);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
@@ -238,15 +214,15 @@ void tst_QPdfWriter::testPageMetrics()
// Now while in Landscape mode, set the size again, results should be the same
writer.setPageSize(pageSize);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), int(pageSizeId));
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);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));