From 1f35be2f3888b34b4a2f4280c7e0a482bca47640 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 23 Aug 2022 20:07:50 +0200 Subject: tests: Fix tst_qprinterinfo for CUPS printer instances CUPS has a feature called printer instances that allows saving different sets of default options for a single print queue, s. section "Creating Saved Options" at [1]. A printer instance can be set up using e.g. lpoptions -p printer/instance -o name=value The printer instance is then listed with the print queue name and the instance name separated by a slash in the 'lpstat -e' output. Qt also supports CUPS printer instances and displays them using the same as printer names. However, tst_QPrinterInfo::getPrintersFromSystem was previously truncating the printer name at the slash, so the comparison of printer names on a system that has CUPS printer instances set up would fail e.g. as follows: ********* Start testing of tst_QPrinterInfo ********* Config: Using QtTest library 6.5.0, Qt 6.5.0 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 12.1.0), debian unknown PASS : tst_QPrinterInfo::initTestCase() QDEBUG : tst_QPrinterInfo::testForDefaultPrinter() Test believes Default Printer = "PDF" QDEBUG : tst_QPrinterInfo::testForDefaultPrinter() QPrinterInfo::defaultPrinter() believes Default Printer = "PDF" QDEBUG : tst_QPrinterInfo::testForDefaultPrinter() QPrinterInfo::availablePrinters() believes Default Printer = "PDF" PASS : tst_QPrinterInfo::testForDefaultPrinter() QDEBUG : tst_QPrinterInfo::testForPrinters() Test believes Available Printers = QList("Canon_MX390_series", "PDF", "PDF", "PDF-5cm-margins", "dummy", "dummy-ricoh-c3000", "tofile-hp-officejet-8600", "tofile-ricoh-aficio", "tofile-ricoh-mufu", "tofile-samsung-m2875", "tofile-test-tdf106963", "tofile-xerox-phaser-6510") QDEBUG : tst_QPrinterInfo::testForPrinters() QPrinterInfo::availablePrinters() believes Available Printers = QList("Canon_MX390_series", "PDF", "PDF-5cm-margins", "PDF/myinstance", "dummy", "dummy-ricoh-c3000", "tofile-hp-officejet-8600", "tofile-ricoh-aficio", "tofile-ricoh-mufu", "tofile-samsung-m2875", "tofile-test-tdf106963", "tofile-xerox-phaser-6510") FAIL! : tst_QPrinterInfo::testForPrinters() Compared values are not the same Actual (qtPrinters.at(i)) : "PDF-5cm-margins" Expected (testPrinters.at(i)): "PDF" Loc: [/home/michi/development/git/qt5/qtbase/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp(232)] Fix this by adding the slash character to the regex. [1] https://www.cups.org/doc/options.html Change-Id: Id0dc27a8b4c592847ed364cebf277e988039cad4 Reviewed-by: Albert Astals Cid --- tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/printsupport/kernel/qprinterinfo') diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp index adf4cb7181..c883df8637 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp +++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp @@ -94,7 +94,7 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem() QString output = getOutputFromCommand({ "lpstat", "-e" }); QStringList list = output.split(QChar::fromLatin1('\n')); - QRegularExpression reg("^([.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]); -- cgit v1.2.3