diff options
Diffstat (limited to 'tests/auto/printsupport/kernel/qprinter')
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/qprinter.pro | 4 | ||||
-rw-r--r-- | tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp | 71 |
3 files changed, 37 insertions, 51 deletions
diff --git a/tests/auto/printsupport/kernel/qprinter/CMakeLists.txt b/tests/auto/printsupport/kernel/qprinter/CMakeLists.txt index bd1b5d1033..c861a122d9 100644 --- a/tests/auto/printsupport/kernel/qprinter/CMakeLists.txt +++ b/tests/auto/printsupport/kernel/qprinter/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qprinter.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qprinter Test: ##################################################################### -qt_add_test(tst_qprinter +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qprinter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qprinter SOURCES tst_qprinter.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::PrintSupport Qt::Widgets diff --git a/tests/auto/printsupport/kernel/qprinter/qprinter.pro b/tests/auto/printsupport/kernel/qprinter/qprinter.pro deleted file mode 100644 index 462929c153..0000000000 --- a/tests/auto/printsupport/kernel/qprinter/qprinter.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qprinter -QT += printsupport widgets testlib -SOURCES += tst_qprinter.cpp diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index fef7c4905d..d2ccf7b990 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -1,32 +1,7 @@ -/**************************************************************************** -** -** 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 <qprinter.h> #include <qpagesetupdialog.h> @@ -45,7 +20,7 @@ #include <math.h> #ifdef Q_OS_WIN -#include <windows.h> +#include <qt_windows.h> #endif #if QT_CONFIG(printer) @@ -232,7 +207,7 @@ void tst_QPrinter::testPageRectAndPaperRect() QFETCH(int, resolution); QFETCH(bool, doPaperRect); - QPainter *painter = 0; + QPainter *painter = nullptr; printer->setPageOrientation(orientation); printer->setOutputFileName(testFileName(QLatin1String("silly"), QString())); @@ -246,7 +221,7 @@ void tst_QPrinter::testPageRectAndPaperRect() QRect otherRect = (doPaperRect ? printer->paperRect(QPrinter::DevicePixel) : printer->pageRect(QPrinter::DevicePixel)).toRect(); float otherInchesX = float(otherRect.width()) / float(printer->resolution()); float otherInchesY = float(otherRect.height()) / float(printer->resolution()); - if (painter != 0) + if (painter != nullptr) delete painter; QVERIFY(qAbs(otherInchesX - inchesX) < 0.01); @@ -282,7 +257,7 @@ void tst_QPrinter::testMargins() QFETCH(QPageLayout::Orientation, orientation); QFETCH(QPageSize::PageSizeId, pagesize); QFETCH(bool, fullpage); - QPainter *painter = 0; + QPainter *painter = nullptr; printer->setOutputFileName(testFileName(QLatin1String("silly"), QString())); printer->setPageOrientation(orientation); printer->setFullPage(fullpage); @@ -928,7 +903,8 @@ void tst_QPrinter::duplex() QPrinter::DuplexMode expected = printerInfo.defaultDuplexMode(); QCOMPARE(native.duplex(), expected); // Test set/get (skipping Auto as that will return something different) - foreach (QPrinter::DuplexMode mode, printerInfo.supportedDuplexModes()) { + const auto supported = printerInfo.supportedDuplexModes(); + for (QPrinter::DuplexMode mode : supported) { if (mode != expected && mode != QPrinter::DuplexAuto) { expected = mode; break; @@ -937,11 +913,10 @@ void tst_QPrinter::duplex() native.setDuplex(expected); QCOMPARE(native.duplex(), expected); - // Test value preservation + // Test that PdfFormat printer has no duplex. native.setOutputFormat(QPrinter::PdfFormat); - QCOMPARE(native.duplex(), expected); + QCOMPARE(native.duplex(), QPrinter::DuplexNone); native.setOutputFormat(QPrinter::NativeFormat); - QCOMPARE(native.duplex(), expected); // Test setting invalid option if (!printerInfo.supportedDuplexModes().contains(QPrinter::DuplexLongSide)) { @@ -1219,7 +1194,8 @@ void tst_QPrinter::paperSource() QPrinter::PaperSource expected = QPrinter::Manual; #ifdef Q_OS_WIN expected = QPrinter::Auto; - foreach (QPrinter::PaperSource supported, native.supportedPaperSources()) { + const auto sources = native.supportedPaperSources(); + for (QPrinter::PaperSource supported : sources) { if (supported != QPrinter::Auto) { expected = supported; break; @@ -1341,7 +1317,8 @@ void tst_QPrinter::printerName() // Test set/get QString expected = QPrinterInfo::defaultPrinter().printerName(); - foreach (const QPrinterInfo &available, QPrinterInfo::availablePrinters()) { + const auto allAvailable = QPrinterInfo::availablePrinters(); + for (const QPrinterInfo &available : allAvailable) { if (available.printerName() != expected) { expected = available.printerName(); break; @@ -1434,7 +1411,7 @@ void tst_QPrinter::resolution() #ifdef Q_OS_MAC // QMacPrintEngine chooses the closest supported resolution. const QList<int> all_supported = native.supportedResolutions(); - foreach (int supported, all_supported) { + for (int supported : all_supported) { // Test setting a supported resolution int requested = supported; native.setResolution(requested); @@ -1516,7 +1493,13 @@ void tst_QPrinter::outputFormat() QCOMPARE(printer.printerName(), QString()); } else { QCOMPARE(printer.outputFormat(), QPrinter::NativeFormat); - QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName()); + + // If no printer is default, the first available printer should be used. + // Otherwise, the default printer should be used. + if (QPrinterInfo::defaultPrinter().isNull()) + QCOMPARE(printer.printerName(), QPrinterInfo::availablePrinters().at(0).printerName()); + else + QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName()); } printer.setOutputFormat(QPrinter::PdfFormat); @@ -1722,7 +1705,7 @@ void tst_QPrinter::reusePageMetrics() QPrinter defaultP; QPrinterInfo info(defaultP); QString otherPrinterName; - for (QPrinterInfo i : qAsConst(availablePrinters)) { + for (QPrinterInfo i : std::as_const(availablePrinters)) { if (i.printerName() != defaultP.printerName()) { otherPrinterName = i.printerName(); break; @@ -1732,9 +1715,9 @@ void tst_QPrinter::reusePageMetrics() QList<QPageSize> defaultPageSizes = info.supportedPageSizes(); QList<QPageSize> otherPageSizes = QPrinterInfo(otherP).supportedPageSizes(); QPageSize unavailableSizeToSet; - for (QPageSize s : qAsConst(defaultPageSizes)) { + for (QPageSize s : std::as_const(defaultPageSizes)) { bool found = false; - for (QPageSize os : qAsConst(otherPageSizes)) { + for (QPageSize os : std::as_const(otherPageSizes)) { if (os.isEquivalentTo(s)) { found = true; break; |