diff options
Diffstat (limited to 'tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp')
-rw-r--r-- | tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp | 78 |
1 files changed, 22 insertions, 56 deletions
diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp index 81b49a3a87..110f2996fd 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp +++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp @@ -1,42 +1,18 @@ -/**************************************************************************** -** -** 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 <QtPrintSupport/qprinterinfo.h> #include <algorithm> -#ifdef Q_OS_UNIX +#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_VXWORKS) # include <unistd.h> # include <sys/types.h> # include <sys/wait.h> +# define USE_PIPE_EXEC #endif @@ -63,9 +39,9 @@ private: QString getDefaultPrinterFromSystem(); QStringList getPrintersFromSystem(); -#ifdef Q_OS_UNIX +#ifdef USE_PIPE_EXEC QString getOutputFromCommand(const QStringList& command); -#endif // Q_OS_UNIX +#endif // USE_PIPE_EXEC #endif }; @@ -73,6 +49,10 @@ private: #ifdef QT_NO_PRINTER void tst_QPrinterInfo::initTestCase() { +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() == 33) + QSKIP("Is flaky on Android 13 / RHEL 8.6 and 8.8 (QTQAINFRA-5606)"); +#endif QSKIP("This test requires printing support"); } @@ -89,7 +69,7 @@ QString tst_QPrinterInfo::getDefaultPrinterFromSystem() #ifdef Q_OS_WIN32 // TODO "cscript c:\windows\system32\prnmngr.vbs -g" #endif // Q_OS_WIN32 -#ifdef Q_OS_UNIX +#ifdef USE_PIPE_EXEC QStringList command; command << "lpstat" << "-d"; QString output = getOutputFromCommand(command); @@ -103,7 +83,7 @@ QString tst_QPrinterInfo::getDefaultPrinterFromSystem() QRegularExpression defaultReg("default.*: *([a-zA-Z0-9_-]+)"); match = defaultReg.match(output); printer = match.captured(1); -#endif // Q_OS_UNIX +#endif // USE_PIPE_EXEC return printer; } @@ -114,13 +94,11 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem() #ifdef Q_OS_WIN32 // TODO "cscript c:\windows\system32\prnmngr.vbs -l" #endif // Q_OS_WIN32 -#ifdef Q_OS_UNIX - QStringList command; - command << "lpstat" << "-p"; - QString output = getOutputFromCommand(command); +#ifdef USE_PIPE_EXEC + QString output = getOutputFromCommand({ "lpstat", "-e" }); QStringList list = output.split(QChar::fromLatin1('\n')); - QRegularExpression reg("^[Pp]rinter ([.a-zA-Z0-9-_@]+)"); + QRegularExpression reg("^([.a-zA-Z0-9-_@/]+)"); QRegularExpressionMatch match; for (int c = 0; c < list.size(); ++c) { match = reg.match(list[c]); @@ -129,12 +107,12 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem() ans << printer; } } -#endif // Q_OS_UNIX +#endif // USE_PIPE_EXEC return ans; } -#ifdef Q_OS_UNIX +#ifdef USE_PIPE_EXEC // This function does roughly the same as the `command substitution` in // the shell. QString getOutputFromCommandInternal(const QStringList &command) @@ -200,7 +178,7 @@ QString tst_QPrinterInfo::getOutputFromCommand(const QStringList &command) { // Forces the ouptut from the command to be in English const QByteArray origSoftwareEnv = qgetenv("SOFTWARE"); - qputenv("SOFTWARE", QByteArray()); + qputenv("SOFTWARE", nullptr); QString output = getOutputFromCommandInternal(command); qputenv("SOFTWARE", origSoftwareEnv); return output; @@ -302,12 +280,6 @@ void tst_QPrinterInfo::testConstructors() QCOMPARE(copy1.minimumPhysicalPageSize(), printers.at(i).minimumPhysicalPageSize()); QCOMPARE(copy1.maximumPhysicalPageSize(), printers.at(i).maximumPhysicalPageSize()); QCOMPARE(copy1.supportedPageSizes(), printers.at(i).supportedPageSizes()); -#if QT_DEPRECATED_SINCE(5, 3) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - QCOMPARE(copy1.supportedSizesWithNames(), printers.at(i).supportedSizesWithNames()); -QT_WARNING_POP -#endif QCOMPARE(copy1.supportedResolutions(), printers.at(i).supportedResolutions()); QCOMPARE(copy1.defaultDuplexMode(), printers.at(i).defaultDuplexMode()); QCOMPARE(copy1.supportedDuplexModes(), printers.at(i).supportedDuplexModes()); @@ -328,12 +300,6 @@ QT_WARNING_POP QCOMPARE(copy2.minimumPhysicalPageSize(), printers.at(i).minimumPhysicalPageSize()); QCOMPARE(copy2.maximumPhysicalPageSize(), printers.at(i).maximumPhysicalPageSize()); QCOMPARE(copy2.supportedPageSizes(), printers.at(i).supportedPageSizes()); -#if QT_DEPRECATED_SINCE(5, 3) - QT_WARNING_PUSH - QT_WARNING_DISABLE_DEPRECATED - QCOMPARE(copy2.supportedSizesWithNames(), printers.at(i).supportedSizesWithNames()); - QT_WARNING_POP -#endif QCOMPARE(copy2.supportedResolutions(), printers.at(i).supportedResolutions()); QCOMPARE(copy2.defaultDuplexMode(), printers.at(i).defaultDuplexMode()); QCOMPARE(copy2.supportedDuplexModes(), printers.at(i).supportedDuplexModes()); @@ -374,11 +340,11 @@ void tst_QPrinterInfo::testAssignment() void tst_QPrinterInfo::namedPrinter() { - QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters(); + const QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters(); QStringList printerNames; - foreach (const QPrinterInfo &pi, printers) { + for (const QPrinterInfo &pi : printers) { QPrinterInfo pi2 = QPrinterInfo::printerInfo(pi.printerName()); QCOMPARE(pi2.printerName(), pi.printerName()); QCOMPARE(pi2.description(), pi.description()); |