author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:20:32 +0300 | |
changeset 34 | a33bf25e6f72 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
||
46 |
||
47 |
#include <qprinter.h> |
|
48 |
#include <qpagesetupdialog.h> |
|
49 |
#include <qpainter.h> |
|
50 |
#include <qprintdialog.h> |
|
51 |
#include <qprinterinfo.h> |
|
52 |
#ifdef QT3_SUPPORT |
|
53 |
#include <q3paintdevicemetrics.h> |
|
54 |
#endif |
|
55 |
#include <qvariant.h> |
|
56 |
#include <qpainter.h> |
|
57 |
#include <qprintengine.h> |
|
58 |
||
59 |
#include <math.h> |
|
60 |
||
61 |
#ifdef Q_WS_WIN |
|
62 |
#include <windows.h> |
|
63 |
#endif |
|
64 |
||
65 |
Q_DECLARE_METATYPE(QRect) |
|
66 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
67 |
QT_FORWARD_DECLARE_CLASS(QPrinter) |
0 | 68 |
|
69 |
//TESTED_CLASS= |
|
70 |
//TESTED_FILES= |
|
71 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
72 |
#ifndef QT_NO_PRINTER |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
73 |
|
0 | 74 |
class tst_QPrinter : public QObject |
75 |
{ |
|
76 |
Q_OBJECT |
|
77 |
||
78 |
public: |
|
79 |
tst_QPrinter(); |
|
80 |
virtual ~tst_QPrinter(); |
|
81 |
||
82 |
||
83 |
public slots: |
|
84 |
void initTestCase(); |
|
85 |
void cleanupTestCase(); |
|
86 |
void init(); |
|
87 |
void cleanup(); |
|
88 |
private slots: |
|
89 |
void getSetCheck(); |
|
90 |
// Add your testfunctions and testdata create functions here |
|
91 |
void testPageSize(); |
|
92 |
void testPageRectAndPaperRect(); |
|
93 |
void testPageRectAndPaperRect_data(); |
|
94 |
void testSetOptions(); |
|
95 |
void testMargins_data(); |
|
96 |
void testMargins(); |
|
97 |
void testNonExistentPrinter(); |
|
98 |
void testPageSetupDialog(); |
|
99 |
void testMulitpleSets_data(); |
|
100 |
void testMulitpleSets(); |
|
101 |
void testPageMargins_data(); |
|
102 |
void testPageMargins(); |
|
103 |
void changingOutputFormat(); |
|
104 |
void outputFormatFromSuffix(); |
|
105 |
void setGetPaperSize(); |
|
106 |
void valuePreservation(); |
|
107 |
void errorReporting(); |
|
108 |
void testCustomPageSizes(); |
|
109 |
void printDialogCompleter(); |
|
110 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
111 |
void testCopyCount(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
112 |
void testCurrentPage(); |
0 | 113 |
|
114 |
void taskQTBUG4497_reusePrinterOnDifferentFiles(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
115 |
void testPdfTitle(); |
0 | 116 |
|
117 |
private: |
|
118 |
}; |
|
119 |
||
120 |
// Testing get/set functions |
|
121 |
void tst_QPrinter::getSetCheck() |
|
122 |
{ |
|
123 |
QPrinter obj1; |
|
124 |
// OutputFormat QPrinter::outputFormat() |
|
125 |
// void QPrinter::setOutputFormat(OutputFormat) |
|
126 |
obj1.setOutputFormat(QPrinter::OutputFormat(QPrinter::PdfFormat)); |
|
127 |
QCOMPARE(QPrinter::OutputFormat(QPrinter::PdfFormat), obj1.outputFormat()); |
|
128 |
||
129 |
// bool QPrinter::collateCopies() |
|
130 |
// void QPrinter::setCollateCopies(bool) |
|
131 |
obj1.setCollateCopies(false); |
|
132 |
QCOMPARE(false, obj1.collateCopies()); |
|
133 |
obj1.setCollateCopies(true); |
|
134 |
QCOMPARE(true, obj1.collateCopies()); |
|
135 |
||
136 |
obj1.setColorMode(QPrinter::GrayScale); |
|
137 |
QCOMPARE(obj1.colorMode(), QPrinter::GrayScale); |
|
138 |
obj1.setColorMode(QPrinter::Color); |
|
139 |
QCOMPARE(obj1.colorMode(), QPrinter::Color); |
|
140 |
||
141 |
obj1.setCreator(QString::fromLatin1("RandomQtUser")); |
|
142 |
QCOMPARE(obj1.creator(), QString::fromLatin1("RandomQtUser")); |
|
143 |
||
144 |
obj1.setDocName(QString::fromLatin1("RandomQtDocument")); |
|
145 |
QCOMPARE(obj1.docName(), QString::fromLatin1("RandomQtDocument")); |
|
146 |
||
147 |
obj1.setDoubleSidedPrinting(true); |
|
148 |
QCOMPARE(obj1.doubleSidedPrinting(), true); |
|
149 |
obj1.setDoubleSidedPrinting(false); |
|
150 |
QCOMPARE(obj1.doubleSidedPrinting(), false); |
|
151 |
||
152 |
obj1.setFromTo(1, 4); |
|
153 |
QCOMPARE(obj1.fromPage(), 1); |
|
154 |
QCOMPARE(obj1.toPage(), 4); |
|
155 |
||
156 |
obj1.setFullPage(true); |
|
157 |
QCOMPARE(obj1.fullPage(), true); |
|
158 |
obj1.setFullPage(false); |
|
159 |
QCOMPARE(obj1.fullPage(), false); |
|
160 |
||
161 |
obj1.setOrientation(QPrinter::Landscape); |
|
162 |
QCOMPARE(obj1.orientation(), QPrinter::Landscape); |
|
163 |
obj1.setOrientation(QPrinter::Portrait); |
|
164 |
QCOMPARE(obj1.orientation(), QPrinter::Portrait); |
|
165 |
||
166 |
obj1.setOutputFileName(QString::fromLatin1("RandomQtName")); |
|
167 |
QCOMPARE(obj1.outputFileName(), QString::fromLatin1("RandomQtName")); |
|
168 |
||
169 |
obj1.setPageOrder(QPrinter::FirstPageFirst); |
|
170 |
QCOMPARE(obj1.pageOrder(), QPrinter::FirstPageFirst); |
|
171 |
obj1.setPageOrder(QPrinter::LastPageFirst); |
|
172 |
QCOMPARE(obj1.pageOrder(), QPrinter::LastPageFirst); |
|
173 |
||
174 |
obj1.setPaperSource(QPrinter::Cassette); |
|
175 |
QCOMPARE(obj1.paperSource(), QPrinter::Cassette); |
|
176 |
obj1.setPaperSource(QPrinter::Middle); |
|
177 |
QCOMPARE(obj1.paperSource(), QPrinter::Middle); |
|
178 |
||
179 |
#ifdef Q_OS_UNIX |
|
180 |
obj1.setPrintProgram(QString::fromLatin1("/bin/true")); |
|
181 |
QCOMPARE(obj1.printProgram(), QString::fromLatin1("/bin/true")); |
|
182 |
||
183 |
obj1.setPrinterSelectionOption(QString::fromLatin1("--option")); |
|
184 |
QCOMPARE(obj1.printerSelectionOption(), QString::fromLatin1("--option")); |
|
185 |
#endif |
|
186 |
||
187 |
obj1.setPrinterName(QString::fromLatin1("myPrinter")); |
|
188 |
QCOMPARE(obj1.printerName(), QString::fromLatin1("myPrinter")); |
|
189 |
||
190 |
// bool QPrinter::fontEmbeddingEnabled() |
|
191 |
// void QPrinter::setFontEmbeddingEnabled(bool) |
|
192 |
obj1.setFontEmbeddingEnabled(false); |
|
193 |
QCOMPARE(false, obj1.fontEmbeddingEnabled()); |
|
194 |
obj1.setFontEmbeddingEnabled(true); |
|
195 |
QCOMPARE(true, obj1.fontEmbeddingEnabled()); |
|
196 |
||
197 |
// PageSize QPrinter::pageSize() |
|
198 |
// void QPrinter::setPageSize(PageSize) |
|
199 |
obj1.setPageSize(QPrinter::PageSize(QPrinter::A4)); |
|
200 |
QCOMPARE(QPrinter::PageSize(QPrinter::A4), obj1.pageSize()); |
|
201 |
obj1.setPageSize(QPrinter::PageSize(QPrinter::Letter)); |
|
202 |
QCOMPARE(QPrinter::PageSize(QPrinter::Letter), obj1.pageSize()); |
|
203 |
obj1.setPageSize(QPrinter::PageSize(QPrinter::Legal)); |
|
204 |
QCOMPARE(QPrinter::PageSize(QPrinter::Legal), obj1.pageSize()); |
|
205 |
||
206 |
// PrintRange QPrinter::printRange() |
|
207 |
// void QPrinter::setPrintRange(PrintRange) |
|
208 |
obj1.setPrintRange(QPrinter::PrintRange(QPrinter::AllPages)); |
|
209 |
QCOMPARE(QPrinter::PrintRange(QPrinter::AllPages), obj1.printRange()); |
|
210 |
obj1.setPrintRange(QPrinter::PrintRange(QPrinter::Selection)); |
|
211 |
QCOMPARE(QPrinter::PrintRange(QPrinter::Selection), obj1.printRange()); |
|
212 |
obj1.setPrintRange(QPrinter::PrintRange(QPrinter::PageRange)); |
|
213 |
QCOMPARE(QPrinter::PrintRange(QPrinter::PageRange), obj1.printRange()); |
|
214 |
} |
|
215 |
||
216 |
tst_QPrinter::tst_QPrinter() |
|
217 |
{ |
|
218 |
} |
|
219 |
||
220 |
tst_QPrinter::~tst_QPrinter() |
|
221 |
{ |
|
222 |
} |
|
223 |
||
224 |
// initTestCase will be executed once before the first testfunction is executed. |
|
225 |
void tst_QPrinter::initTestCase() |
|
226 |
{ |
|
227 |
// TODO: Add testcase generic initialization code here. |
|
228 |
// suggestion: |
|
229 |
// testWidget = new QPrinter(0,"testWidget"); |
|
230 |
// testWidget->setFixedSize(200, 200); |
|
231 |
// qApp->setMainWidget(testWidget); |
|
232 |
// testWidget->show(); |
|
233 |
} |
|
234 |
||
235 |
// cleanupTestCase will be executed once after the last testfunction is executed. |
|
236 |
void tst_QPrinter::cleanupTestCase() |
|
237 |
{ |
|
238 |
// TODO: Add testcase generic cleanup code here. |
|
239 |
// suggestion: |
|
240 |
// testWidget->hide(); |
|
241 |
// qApp->setMainWidget(0); |
|
242 |
// delete testWidget; |
|
243 |
} |
|
244 |
||
245 |
// init() will be executed immediately before each testfunction is run. |
|
246 |
void tst_QPrinter::init() |
|
247 |
{ |
|
248 |
// TODO: Add testfunction specific initialization code here. |
|
249 |
} |
|
250 |
||
251 |
// cleanup() will be executed immediately after each testfunction is run. |
|
252 |
void tst_QPrinter::cleanup() |
|
253 |
{ |
|
254 |
// TODO: Add testfunction specific cleanup code here. |
|
255 |
} |
|
256 |
||
257 |
#define MYCOMPARE(a, b) QCOMPARE(QVariant((int)a), QVariant((int)b)) |
|
258 |
||
259 |
void tst_QPrinter::testPageSetupDialog() |
|
260 |
{ |
|
261 |
// Make sure this doesn't crash at least |
|
262 |
{ |
|
263 |
QPrinter printer; |
|
264 |
QPageSetupDialog dialog(&printer); |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
void tst_QPrinter::testPageSize() |
|
269 |
{ |
|
270 |
#if defined (Q_WS_WIN) |
|
271 |
QPrinter prn; |
|
272 |
||
273 |
prn.setPageSize(QPrinter::Letter); |
|
274 |
MYCOMPARE(prn.pageSize(), QPrinter::Letter); |
|
275 |
MYCOMPARE(prn.winPageSize(), DMPAPER_LETTER); |
|
276 |
||
277 |
prn.setPageSize(QPrinter::A4); |
|
278 |
MYCOMPARE(prn.pageSize(), QPrinter::A4); |
|
279 |
MYCOMPARE(prn.winPageSize(), DMPAPER_A4); |
|
280 |
||
281 |
prn.setWinPageSize(DMPAPER_LETTER); |
|
282 |
MYCOMPARE(prn.winPageSize(), DMPAPER_LETTER); |
|
283 |
MYCOMPARE(prn.pageSize(), QPrinter::Letter); |
|
284 |
||
285 |
prn.setWinPageSize(DMPAPER_A4); |
|
286 |
MYCOMPARE(prn.winPageSize(), DMPAPER_A4); |
|
287 |
MYCOMPARE(prn.pageSize(), QPrinter::A4); |
|
288 |
#else |
|
289 |
QSKIP("QPrinter::winPageSize() does not exist for nonwindows platforms", SkipAll); |
|
290 |
#endif |
|
291 |
} |
|
292 |
||
293 |
void tst_QPrinter::testPageRectAndPaperRect_data() |
|
294 |
{ |
|
295 |
QTest::addColumn<int>("orientation"); |
|
296 |
QTest::addColumn<bool>("withPainter"); |
|
297 |
QTest::addColumn<int>("resolution"); |
|
298 |
QTest::addColumn<bool>("doPaperRect"); |
|
299 |
||
300 |
// paperrect |
|
301 |
QTest::newRow("paperRect0") << int(QPrinter::Portrait) << true << 300 << true; |
|
302 |
QTest::newRow("paperRect1") << int(QPrinter::Portrait) << false << 300 << true; |
|
303 |
QTest::newRow("paperRect2") << int(QPrinter::Landscape) << true << 300 << true; |
|
304 |
QTest::newRow("paperRect3") << int(QPrinter::Landscape) << false << 300 << true; |
|
305 |
QTest::newRow("paperRect4") << int(QPrinter::Portrait) << true << 600 << true; |
|
306 |
QTest::newRow("paperRect5") << int(QPrinter::Portrait) << false << 600 << true; |
|
307 |
QTest::newRow("paperRect6") << int(QPrinter::Landscape) << true << 600 << true; |
|
308 |
QTest::newRow("paperRect7") << int(QPrinter::Landscape) << false << 600 << true; |
|
309 |
QTest::newRow("paperRect8") << int(QPrinter::Portrait) << true << 1200 << true; |
|
310 |
QTest::newRow("paperRect9") << int(QPrinter::Portrait) << false << 1200 << true; |
|
311 |
QTest::newRow("paperRect10") << int(QPrinter::Landscape) << true << 1200 << true; |
|
312 |
QTest::newRow("paperRect11") << int(QPrinter::Landscape) << false << 1200 << true; |
|
313 |
||
314 |
// page rect |
|
315 |
QTest::newRow("pageRect0") << int(QPrinter::Portrait) << true << 300 << false; |
|
316 |
QTest::newRow("pageRect1") << int(QPrinter::Portrait) << false << 300 << false; |
|
317 |
QTest::newRow("pageRect2") << int(QPrinter::Landscape) << true << 300 << false; |
|
318 |
QTest::newRow("pageRect3") << int(QPrinter::Landscape) << false << 300 << false; |
|
319 |
QTest::newRow("pageRect4") << int(QPrinter::Portrait) << true << 600 << false; |
|
320 |
QTest::newRow("pageRect5") << int(QPrinter::Portrait) << false << 600 << false; |
|
321 |
QTest::newRow("pageRect6") << int(QPrinter::Landscape) << true << 600 << false; |
|
322 |
QTest::newRow("pageRect7") << int(QPrinter::Landscape) << false << 600 << false; |
|
323 |
QTest::newRow("pageRect8") << int(QPrinter::Portrait) << true << 1200 << false; |
|
324 |
QTest::newRow("pageRect9") << int(QPrinter::Portrait) << false << 1200 << false; |
|
325 |
QTest::newRow("pageRect10") << int(QPrinter::Landscape) << true << 1200 << false; |
|
326 |
QTest::newRow("pageRect11") << int(QPrinter::Landscape) << false << 1200 << false; |
|
327 |
} |
|
328 |
||
329 |
void tst_QPrinter::testPageRectAndPaperRect() |
|
330 |
{ |
|
331 |
QFETCH(bool, withPainter); |
|
332 |
QFETCH(int, orientation); |
|
333 |
QFETCH(int, resolution); |
|
334 |
QFETCH(bool, doPaperRect); |
|
335 |
||
336 |
QPainter *painter = 0; |
|
337 |
QPrinter printer(QPrinter::HighResolution); |
|
338 |
printer.setOrientation(QPrinter::Orientation(orientation)); |
|
339 |
printer.setOutputFileName("silly"); |
|
340 |
||
341 |
QRect pageRect = doPaperRect ? printer.paperRect() : printer.pageRect(); |
|
342 |
float inchesX = float(pageRect.width()) / float(printer.resolution()); |
|
343 |
float inchesY = float(pageRect.height()) / float(printer.resolution()); |
|
344 |
printer.setResolution(resolution); |
|
345 |
if (withPainter) |
|
346 |
painter = new QPainter(&printer); |
|
347 |
||
348 |
QRect otherRect = doPaperRect ? printer.paperRect() : printer.pageRect(); |
|
349 |
float otherInchesX = float(otherRect.width()) / float(printer.resolution()); |
|
350 |
float otherInchesY = float(otherRect.height()) / float(printer.resolution()); |
|
351 |
if (painter != 0) |
|
352 |
delete painter; |
|
353 |
||
354 |
QVERIFY(qAbs(otherInchesX - inchesX) < 0.01); |
|
355 |
QVERIFY(qAbs(otherInchesY - inchesY) < 0.01); |
|
356 |
||
357 |
QVERIFY(printer.orientation() == QPrinter::Portrait || pageRect.width() > pageRect.height()); |
|
358 |
QVERIFY(printer.orientation() != QPrinter::Portrait || pageRect.width() < pageRect.height()); |
|
359 |
} |
|
360 |
||
361 |
void tst_QPrinter::testSetOptions() |
|
362 |
{ |
|
363 |
QPrinter prn; |
|
364 |
QPrintDialog dlg(&prn); |
|
365 |
||
366 |
// Verify default values |
|
367 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), TRUE); |
|
368 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), FALSE); |
|
369 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), TRUE); |
|
370 |
||
371 |
dlg.setEnabledOptions(QAbstractPrintDialog::PrintPageRange); |
|
372 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), FALSE); |
|
373 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), FALSE); |
|
374 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), TRUE); |
|
375 |
||
376 |
dlg.setEnabledOptions((QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection |
|
377 |
| QAbstractPrintDialog::PrintPageRange))); |
|
378 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), FALSE); |
|
379 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), TRUE); |
|
380 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), TRUE); |
|
381 |
||
382 |
dlg.setEnabledOptions(QAbstractPrintDialog::PrintSelection); |
|
383 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), FALSE); |
|
384 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), TRUE); |
|
385 |
MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), FALSE); |
|
386 |
} |
|
387 |
||
388 |
void tst_QPrinter::testMargins_data() |
|
389 |
{ |
|
390 |
QTest::addColumn<int>("orientation"); |
|
391 |
QTest::addColumn<bool>("fullpage"); |
|
392 |
QTest::addColumn<int>("pagesize"); |
|
393 |
QTest::addColumn<int>("width"); |
|
394 |
QTest::addColumn<int>("height"); |
|
395 |
QTest::addColumn<bool>("withPainter"); |
|
396 |
||
397 |
QTest::newRow("data0") << int(QPrinter::Portrait) << true << int(QPrinter::A4) << 210 << 297 << false; |
|
398 |
QTest::newRow("data1") << int(QPrinter::Landscape) << true << int(QPrinter::A4) << 297 << 210 << false; |
|
399 |
QTest::newRow("data2") << int(QPrinter::Landscape) << false << int(QPrinter::A4) << 297 << 210 << false; |
|
400 |
QTest::newRow("data3") << int(QPrinter::Portrait) << false << int(QPrinter::A4) << 210 << 297 << false; |
|
401 |
QTest::newRow("data4") << int(QPrinter::Portrait) << true << int(QPrinter::A4) << 210 << 297 << true; |
|
402 |
QTest::newRow("data5") << int(QPrinter::Landscape) << true << int(QPrinter::A4) << 297 << 210 << true; |
|
403 |
QTest::newRow("data6") << int(QPrinter::Landscape) << false << int(QPrinter::A4) << 297 << 210 << true; |
|
404 |
QTest::newRow("data7") << int(QPrinter::Portrait) << false << int(QPrinter::A4) << 210 << 297 << true; |
|
405 |
} |
|
406 |
||
407 |
void tst_QPrinter::testMargins() |
|
408 |
{ |
|
409 |
QFETCH(bool, withPainter); |
|
410 |
QFETCH(int, orientation); |
|
411 |
QFETCH(int, pagesize); |
|
412 |
QFETCH(int, width); |
|
413 |
QFETCH(int, height); |
|
414 |
QFETCH(bool, fullpage); |
|
415 |
QPrinter printer; |
|
416 |
QPainter *painter = 0; |
|
417 |
printer.setOutputFileName("silly"); |
|
418 |
printer.setOrientation((QPrinter::Orientation)orientation); |
|
419 |
printer.setFullPage(fullpage); |
|
420 |
printer.setPageSize((QPrinter::PageSize)pagesize); |
|
421 |
if (withPainter) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
422 |
painter = new QPainter(&printer); |
0 | 423 |
|
424 |
#ifdef QT3_SUPPORT |
|
425 |
Q3PaintDeviceMetrics metrics(&printer); |
|
426 |
int pwidth = metrics.width(); |
|
427 |
int pheight = metrics.height(); |
|
428 |
||
429 |
if (orientation == QPrinter::Portrait) { |
|
430 |
QVERIFY(pheight >= pwidth); |
|
431 |
} else { |
|
432 |
QVERIFY(pwidth >= pheight); |
|
433 |
} |
|
434 |
||
435 |
if (fullpage) { |
|
436 |
QCOMPARE(metrics.widthMM(), width); |
|
437 |
QCOMPARE(metrics.heightMM(), height); |
|
438 |
} |
|
439 |
#endif |
|
440 |
||
441 |
if (painter) |
|
442 |
delete painter; |
|
443 |
} |
|
444 |
||
445 |
void tst_QPrinter::testNonExistentPrinter() |
|
446 |
{ |
|
447 |
#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_MAC) |
|
448 |
QSKIP("QPrinter::testNonExistentPrinter() is not relevant for X11/Embedded/Mac", SkipAll); |
|
449 |
#else |
|
450 |
QPrinter printer; |
|
451 |
QPainter painter; |
|
452 |
||
453 |
// Make sure it doesn't crash on setting or getting properties |
|
454 |
printer.setPrinterName("some non existing printer"); |
|
455 |
printer.setPageSize(QPrinter::A4); |
|
456 |
printer.setOrientation(QPrinter::Portrait); |
|
457 |
printer.setFullPage(true); |
|
458 |
printer.pageSize(); |
|
459 |
printer.orientation(); |
|
460 |
printer.fullPage(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
461 |
printer.setCopyCount(1); |
0 | 462 |
printer.printerName(); |
463 |
||
464 |
// nor metrics |
|
465 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmWidth), 0); |
|
466 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmHeight), 0); |
|
467 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmWidthMM), 0); |
|
468 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmHeightMM), 0); |
|
469 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmNumColors), 0); |
|
470 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmDepth), 0); |
|
471 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmDpiX), 0); |
|
472 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmDpiY), 0); |
|
473 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmPhysicalDpiX), 0); |
|
474 |
QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmPhysicalDpiY), 0); |
|
475 |
||
476 |
QVERIFY(!painter.begin(&printer)); |
|
477 |
#endif |
|
478 |
} |
|
479 |
||
480 |
||
481 |
void tst_QPrinter::testMulitpleSets_data() |
|
482 |
{ |
|
483 |
QTest::addColumn<int>("resolution"); |
|
484 |
QTest::addColumn<int>("pageSize"); |
|
485 |
QTest::addColumn<int>("widthMMAfter"); |
|
486 |
QTest::addColumn<int>("heightMMAfter"); |
|
487 |
||
488 |
||
489 |
QTest::newRow("lowRes") << int(QPrinter::ScreenResolution) << int(QPrinter::A4) << 210 << 297; |
|
490 |
QTest::newRow("lowResLetter") << int(QPrinter::ScreenResolution) << int(QPrinter::Letter) << 216 << 279; |
|
491 |
QTest::newRow("lowResA5") << int(QPrinter::ScreenResolution) << int(QPrinter::A5) << 148 << 210; |
|
492 |
QTest::newRow("midRes") << int(QPrinter::PrinterResolution) << int(QPrinter::A4) << 210 << 297; |
|
493 |
QTest::newRow("midResLetter") << int(QPrinter::PrinterResolution) << int(QPrinter::Letter) << 216 << 279; |
|
494 |
QTest::newRow("midResA5") << int(QPrinter::PrinterResolution) << int(QPrinter::A5) << 148 << 210; |
|
495 |
QTest::newRow("highRes") << int(QPrinter::HighResolution) << int(QPrinter::A4) << 210 << 297; |
|
496 |
QTest::newRow("highResLetter") << int(QPrinter::HighResolution) << int(QPrinter::Letter) << 216 << 279; |
|
497 |
QTest::newRow("highResA5") << int(QPrinter::HighResolution) << int(QPrinter::A5) << 148 << 210; |
|
498 |
} |
|
499 |
||
500 |
static void computePageValue(const QPrinter &printer, int &retWidth, int &retHeight) |
|
501 |
{ |
|
502 |
const double Inch2MM = 25.4; |
|
503 |
||
504 |
double width = double(printer.paperRect().width()) / printer.logicalDpiX() * Inch2MM; |
|
505 |
double height = double(printer.paperRect().height()) / printer.logicalDpiY() * Inch2MM; |
|
506 |
retWidth = qRound(width); |
|
507 |
retHeight = qRound(height); |
|
508 |
} |
|
509 |
||
510 |
void tst_QPrinter::testMulitpleSets() |
|
511 |
{ |
|
512 |
// A very simple test, but Mac needs to have its format "validated" if the format is changed |
|
513 |
// This takes care of that. |
|
514 |
QFETCH(int, resolution); |
|
515 |
QFETCH(int, pageSize); |
|
516 |
QFETCH(int, widthMMAfter); |
|
517 |
QFETCH(int, heightMMAfter); |
|
518 |
||
519 |
||
520 |
QPrinter::PrinterMode mode = QPrinter::PrinterMode(resolution); |
|
521 |
QPrinter::PageSize printerPageSize = QPrinter::PageSize(pageSize); |
|
522 |
QPrinter printer(mode); |
|
523 |
printer.setFullPage(true); |
|
524 |
||
525 |
int paperWidth, paperHeight; |
|
526 |
//const int Tolerance = 2; |
|
527 |
||
528 |
computePageValue(printer, paperWidth, paperHeight); |
|
529 |
printer.setPageSize(printerPageSize); |
|
530 |
||
531 |
if (printer.pageSize() != printerPageSize) { |
|
532 |
QSKIP("Current page size is not supported on this printer", SkipSingle); |
|
533 |
return; |
|
534 |
} |
|
535 |
||
536 |
QCOMPARE(printer.widthMM(), widthMMAfter); |
|
537 |
QCOMPARE(printer.heightMM(), heightMMAfter); |
|
538 |
||
539 |
computePageValue(printer, paperWidth, paperHeight); |
|
540 |
||
541 |
QVERIFY(qAbs(paperWidth - widthMMAfter) <= 2); |
|
542 |
QVERIFY(qAbs(paperHeight - heightMMAfter) <= 2); |
|
543 |
||
544 |
// Set it again and see if it still works. |
|
545 |
printer.setPageSize(printerPageSize); |
|
546 |
QCOMPARE(printer.widthMM(), widthMMAfter); |
|
547 |
QCOMPARE(printer.heightMM(), heightMMAfter); |
|
548 |
||
549 |
printer.setOrientation(QPrinter::Landscape); |
|
550 |
computePageValue(printer, paperWidth, paperHeight); |
|
551 |
QVERIFY(qAbs(paperWidth - heightMMAfter) <= 2); |
|
552 |
QVERIFY(qAbs(paperHeight - widthMMAfter) <= 2); |
|
553 |
} |
|
554 |
||
555 |
void tst_QPrinter::changingOutputFormat() |
|
556 |
{ |
|
557 |
QPrinter p; |
|
558 |
p.setOutputFormat(QPrinter::PostScriptFormat); |
|
559 |
p.setPageSize(QPrinter::A8); |
|
560 |
p.setOutputFormat(QPrinter::PdfFormat); |
|
561 |
QCOMPARE(p.pageSize(), QPrinter::A8); |
|
562 |
} |
|
563 |
||
564 |
void tst_QPrinter::outputFormatFromSuffix() |
|
565 |
{ |
|
566 |
if (QPrinterInfo::availablePrinters().size() == 0) |
|
567 |
QSKIP("No printers available.", SkipAll); |
|
568 |
QPrinter p; |
|
569 |
QVERIFY(p.outputFormat() == QPrinter::NativeFormat); |
|
570 |
p.setOutputFileName("test.ps"); |
|
571 |
QVERIFY(p.outputFormat() == QPrinter::PostScriptFormat); |
|
572 |
p.setOutputFileName("test.pdf"); |
|
573 |
QVERIFY(p.outputFormat() == QPrinter::PdfFormat); |
|
574 |
p.setOutputFileName(QString()); |
|
575 |
QVERIFY(p.outputFormat() == QPrinter::NativeFormat); |
|
576 |
} |
|
577 |
||
578 |
void tst_QPrinter::setGetPaperSize() |
|
579 |
{ |
|
580 |
QPrinter p; |
|
581 |
p.setOutputFormat(QPrinter::PdfFormat); |
|
582 |
QSizeF size(500, 10); |
|
583 |
p.setPaperSize(size, QPrinter::Millimeter); |
|
584 |
QCOMPARE(p.paperSize(QPrinter::Millimeter), size); |
|
585 |
QSizeF ptSize = p.paperSize(QPrinter::Point); |
|
586 |
//qDebug() << ptSize; |
|
587 |
QVERIFY(qAbs(ptSize.width() - size.width() * (72/25.4)) < 1E-4); |
|
588 |
QVERIFY(qAbs(ptSize.height() - size.height() * (72/25.4)) < 1E-4); |
|
589 |
} |
|
590 |
||
591 |
void tst_QPrinter::testPageMargins_data() |
|
592 |
{ |
|
593 |
QTest::addColumn<qreal>("left"); |
|
594 |
QTest::addColumn<qreal>("top"); |
|
595 |
QTest::addColumn<qreal>("right"); |
|
596 |
QTest::addColumn<qreal>("bottom"); |
|
597 |
QTest::addColumn<int>("unit"); |
|
598 |
||
599 |
QTest::newRow("data0") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Millimeter); |
|
600 |
QTest::newRow("data1") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Point); |
|
601 |
QTest::newRow("data2") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Inch); |
|
602 |
QTest::newRow("data3") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Pica); |
|
603 |
QTest::newRow("data4") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Didot); |
|
604 |
QTest::newRow("data5") << 5.5 << 6.5 << 7.5 << 8.5 << static_cast<int>(QPrinter::Cicero); |
|
605 |
} |
|
606 |
||
607 |
void tst_QPrinter::testPageMargins() |
|
608 |
{ |
|
609 |
QPrinter obj1; |
|
610 |
||
611 |
qreal toMillimeters[6]; |
|
612 |
toMillimeters[QPrinter::Millimeter] = 1; |
|
613 |
toMillimeters[QPrinter::Point] = 0.352777778; |
|
614 |
toMillimeters[QPrinter::Inch] = 25.4; |
|
615 |
toMillimeters[QPrinter::Pica] = 4.23333333; |
|
616 |
toMillimeters[QPrinter::Didot] = 0.376; |
|
617 |
toMillimeters[QPrinter::Cicero] = 4.51166667; |
|
618 |
||
619 |
QFETCH(qreal, left); |
|
620 |
QFETCH(qreal, top); |
|
621 |
QFETCH(qreal, right); |
|
622 |
QFETCH(qreal, bottom); |
|
623 |
QFETCH(int, unit); |
|
624 |
||
625 |
qreal nLeft, nTop, nRight, nBottom; |
|
626 |
||
627 |
obj1.setPageMargins(left, top, right, bottom, static_cast<QPrinter::Unit>(unit)); |
|
628 |
||
629 |
qreal tolerance = 0.05; |
|
630 |
||
631 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Millimeter); |
|
632 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Millimeter]) < tolerance); |
|
633 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Millimeter]) < tolerance); |
|
634 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Millimeter]) < tolerance); |
|
635 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Millimeter]) < tolerance); |
|
636 |
||
637 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Point); |
|
638 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Point]) < tolerance); |
|
639 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Point]) < tolerance); |
|
640 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Point]) < tolerance); |
|
641 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Point]) < tolerance); |
|
642 |
||
643 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Inch); |
|
644 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Inch]) < tolerance); |
|
645 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Inch]) < tolerance); |
|
646 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Inch]) < tolerance); |
|
647 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Inch]) < tolerance); |
|
648 |
||
649 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Pica); |
|
650 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Pica]) < tolerance); |
|
651 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Pica]) < tolerance); |
|
652 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Pica]) < tolerance); |
|
653 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Pica]) < tolerance); |
|
654 |
||
655 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Didot); |
|
656 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Didot]) < tolerance); |
|
657 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Didot]) < tolerance); |
|
658 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Didot]) < tolerance); |
|
659 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Didot]) < tolerance); |
|
660 |
||
661 |
obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Cicero); |
|
662 |
QVERIFY(fabs(left*toMillimeters[unit] - nLeft*toMillimeters[QPrinter::Cicero]) < tolerance); |
|
663 |
QVERIFY(fabs(top*toMillimeters[unit] - nTop*toMillimeters[QPrinter::Cicero]) < tolerance); |
|
664 |
QVERIFY(fabs(right*toMillimeters[unit] - nRight*toMillimeters[QPrinter::Cicero]) < tolerance); |
|
665 |
QVERIFY(fabs(bottom*toMillimeters[unit] - nBottom*toMillimeters[QPrinter::Cicero]) < tolerance); |
|
666 |
} |
|
667 |
||
668 |
void tst_QPrinter::valuePreservation() |
|
669 |
{ |
|
670 |
QPrinter::OutputFormat oldFormat = QPrinter::PdfFormat; |
|
671 |
QPrinter::OutputFormat newFormat = QPrinter::PostScriptFormat; |
|
672 |
||
673 |
{ |
|
674 |
QPrinter printer; |
|
675 |
printer.setOutputFormat(oldFormat); |
|
676 |
bool status = printer.collateCopies(); |
|
677 |
printer.setOutputFormat(newFormat); |
|
678 |
printer.setOutputFormat(oldFormat); |
|
679 |
QCOMPARE(printer.collateCopies(), status); |
|
680 |
||
681 |
printer.setCollateCopies(!status); |
|
682 |
printer.setOutputFormat(newFormat); |
|
683 |
QCOMPARE(printer.collateCopies(), !status); |
|
684 |
printer.setOutputFormat(oldFormat); |
|
685 |
QCOMPARE(printer.collateCopies(), !status); |
|
686 |
} |
|
687 |
{ |
|
688 |
QPrinter printer; |
|
689 |
printer.setOutputFormat(oldFormat); |
|
690 |
QPrinter::ColorMode status = printer.colorMode(); |
|
691 |
printer.setOutputFormat(newFormat); |
|
692 |
printer.setOutputFormat(oldFormat); |
|
693 |
QCOMPARE(printer.colorMode(), status); |
|
694 |
||
695 |
printer.setColorMode(QPrinter::ColorMode(!status)); |
|
696 |
printer.setOutputFormat(newFormat); |
|
697 |
QCOMPARE(printer.colorMode(), QPrinter::ColorMode(!status)); |
|
698 |
printer.setOutputFormat(oldFormat); |
|
699 |
QCOMPARE(printer.colorMode(), QPrinter::ColorMode(!status)); |
|
700 |
} |
|
701 |
{ |
|
702 |
QPrinter printer; |
|
703 |
printer.setOutputFormat(oldFormat); |
|
704 |
QString status = printer.creator(); |
|
705 |
printer.setOutputFormat(newFormat); |
|
706 |
printer.setOutputFormat(oldFormat); |
|
707 |
QCOMPARE(printer.creator(), status); |
|
708 |
||
709 |
status = QString::fromLatin1("Mr. Test"); |
|
710 |
printer.setCreator(status); |
|
711 |
printer.setOutputFormat(newFormat); |
|
712 |
QCOMPARE(printer.creator(), status); |
|
713 |
printer.setOutputFormat(oldFormat); |
|
714 |
QCOMPARE(printer.creator(), status); |
|
715 |
} |
|
716 |
{ |
|
717 |
QPrinter printer; |
|
718 |
printer.setOutputFormat(oldFormat); |
|
719 |
QString status = printer.docName(); |
|
720 |
printer.setOutputFormat(newFormat); |
|
721 |
printer.setOutputFormat(oldFormat); |
|
722 |
QCOMPARE(printer.docName(), status); |
|
723 |
||
724 |
status = QString::fromLatin1("Test document"); |
|
725 |
printer.setDocName(status); |
|
726 |
printer.setOutputFormat(newFormat); |
|
727 |
QCOMPARE(printer.docName(), status); |
|
728 |
printer.setOutputFormat(oldFormat); |
|
729 |
QCOMPARE(printer.docName(), status); |
|
730 |
} |
|
731 |
{ |
|
732 |
QPrinter printer; |
|
733 |
printer.setOutputFormat(oldFormat); |
|
734 |
bool status = printer.doubleSidedPrinting(); |
|
735 |
printer.setOutputFormat(newFormat); |
|
736 |
printer.setOutputFormat(oldFormat); |
|
737 |
QCOMPARE(printer.doubleSidedPrinting(), status); |
|
738 |
||
739 |
printer.setDoubleSidedPrinting(!status); |
|
740 |
printer.setOutputFormat(newFormat); |
|
741 |
QCOMPARE(printer.doubleSidedPrinting(), !status); |
|
742 |
printer.setOutputFormat(oldFormat); |
|
743 |
QCOMPARE(printer.doubleSidedPrinting(), !status); |
|
744 |
} |
|
745 |
{ |
|
746 |
QPrinter printer; |
|
747 |
printer.setOutputFormat(oldFormat); |
|
748 |
bool status = printer.fontEmbeddingEnabled(); |
|
749 |
printer.setOutputFormat(newFormat); |
|
750 |
printer.setOutputFormat(oldFormat); |
|
751 |
QCOMPARE(printer.fontEmbeddingEnabled(), status); |
|
752 |
||
753 |
printer.setFontEmbeddingEnabled(!status); |
|
754 |
printer.setOutputFormat(newFormat); |
|
755 |
QCOMPARE(printer.fontEmbeddingEnabled(), !status); |
|
756 |
printer.setOutputFormat(oldFormat); |
|
757 |
QCOMPARE(printer.fontEmbeddingEnabled(), !status); |
|
758 |
} |
|
759 |
{ |
|
760 |
QPrinter printer; |
|
761 |
printer.setOutputFormat(oldFormat); |
|
762 |
bool status = printer.fullPage(); |
|
763 |
printer.setOutputFormat(newFormat); |
|
764 |
printer.setOutputFormat(oldFormat); |
|
765 |
QCOMPARE(printer.fullPage(), status); |
|
766 |
||
767 |
printer.setFullPage(!status); |
|
768 |
printer.setOutputFormat(newFormat); |
|
769 |
QCOMPARE(printer.fullPage(), !status); |
|
770 |
printer.setOutputFormat(oldFormat); |
|
771 |
QCOMPARE(printer.fullPage(), !status); |
|
772 |
} |
|
773 |
{ |
|
774 |
QPrinter printer; |
|
775 |
printer.setOutputFormat(oldFormat); |
|
776 |
QPrinter::Orientation status = printer.orientation(); |
|
777 |
printer.setOutputFormat(newFormat); |
|
778 |
printer.setOutputFormat(oldFormat); |
|
779 |
QCOMPARE(printer.orientation(), status); |
|
780 |
||
781 |
printer.setOrientation(QPrinter::Orientation(!status)); |
|
782 |
printer.setOutputFormat(newFormat); |
|
783 |
QCOMPARE(printer.orientation(), QPrinter::Orientation(!status)); |
|
784 |
printer.setOutputFormat(oldFormat); |
|
785 |
QCOMPARE(printer.orientation(), QPrinter::Orientation(!status)); |
|
786 |
} |
|
787 |
{ |
|
788 |
QPrinter printer; |
|
789 |
printer.setOutputFormat(oldFormat); |
|
790 |
QString status = printer.outputFileName(); |
|
791 |
printer.setOutputFormat(newFormat); |
|
792 |
printer.setOutputFormat(oldFormat); |
|
793 |
QCOMPARE(printer.outputFileName(), status); |
|
794 |
||
795 |
status = QString::fromLatin1("Test file"); |
|
796 |
printer.setOutputFileName(status); |
|
797 |
printer.setOutputFormat(newFormat); |
|
798 |
QCOMPARE(printer.outputFileName(), status); |
|
799 |
printer.setOutputFormat(oldFormat); |
|
800 |
QCOMPARE(printer.outputFileName(), status); |
|
801 |
} |
|
802 |
{ |
|
803 |
QPrinter printer; |
|
804 |
printer.setOutputFormat(oldFormat); |
|
805 |
QPrinter::PageOrder status = printer.pageOrder(); |
|
806 |
printer.setOutputFormat(newFormat); |
|
807 |
printer.setOutputFormat(oldFormat); |
|
808 |
QCOMPARE(printer.pageOrder(), status); |
|
809 |
||
810 |
printer.setPageOrder(QPrinter::PageOrder(!status)); |
|
811 |
printer.setOutputFormat(newFormat); |
|
812 |
QCOMPARE(printer.pageOrder(), QPrinter::PageOrder(!status)); |
|
813 |
printer.setOutputFormat(oldFormat); |
|
814 |
QCOMPARE(printer.pageOrder(), QPrinter::PageOrder(!status)); |
|
815 |
} |
|
816 |
{ |
|
817 |
QPrinter printer; |
|
818 |
printer.setOutputFormat(oldFormat); |
|
819 |
QPrinter::PageSize status = printer.pageSize(); |
|
820 |
printer.setOutputFormat(newFormat); |
|
821 |
printer.setOutputFormat(oldFormat); |
|
822 |
QCOMPARE(printer.pageSize(), status); |
|
823 |
||
824 |
printer.setPageSize(QPrinter::B5); |
|
825 |
printer.setOutputFormat(newFormat); |
|
826 |
QCOMPARE(printer.pageSize(), QPrinter::B5); |
|
827 |
printer.setOutputFormat(oldFormat); |
|
828 |
QCOMPARE(printer.pageSize(), QPrinter::B5); |
|
829 |
} |
|
830 |
{ |
|
831 |
QPrinter printer; |
|
832 |
printer.setOutputFormat(oldFormat); |
|
833 |
QPrinter::PaperSource status = printer.paperSource(); |
|
834 |
printer.setOutputFormat(newFormat); |
|
835 |
printer.setOutputFormat(oldFormat); |
|
836 |
QCOMPARE(printer.paperSource(), status); |
|
837 |
||
838 |
printer.setPaperSource(QPrinter::Manual); |
|
839 |
printer.setOutputFormat(newFormat); |
|
840 |
QCOMPARE(printer.paperSource(), QPrinter::Manual); |
|
841 |
printer.setOutputFormat(oldFormat); |
|
842 |
QCOMPARE(printer.paperSource(), QPrinter::Manual); |
|
843 |
} |
|
844 |
{ |
|
845 |
QPrinter printer; |
|
846 |
printer.setOutputFormat(oldFormat); |
|
847 |
QString status = printer.printProgram(); |
|
848 |
printer.setOutputFormat(newFormat); |
|
849 |
printer.setOutputFormat(oldFormat); |
|
850 |
QCOMPARE(printer.printProgram(), status); |
|
851 |
||
852 |
status = QString::fromLatin1("/usr/local/bin/lpr"); |
|
853 |
printer.setPrintProgram(status); |
|
854 |
printer.setOutputFormat(newFormat); |
|
855 |
QCOMPARE(printer.printProgram(), status); |
|
856 |
printer.setOutputFormat(oldFormat); |
|
857 |
QCOMPARE(printer.printProgram(), status); |
|
858 |
} |
|
859 |
{ |
|
860 |
QPrinter printer; |
|
861 |
printer.setOutputFormat(oldFormat); |
|
862 |
QPrinter::PrintRange status = printer.printRange(); |
|
863 |
printer.setOutputFormat(newFormat); |
|
864 |
printer.setOutputFormat(oldFormat); |
|
865 |
QCOMPARE(printer.printRange(), status); |
|
866 |
||
867 |
printer.setPrintRange(QPrinter::PrintRange(!status)); |
|
868 |
printer.setOutputFormat(newFormat); |
|
869 |
QCOMPARE(printer.printRange(), QPrinter::PrintRange(!status)); |
|
870 |
printer.setOutputFormat(oldFormat); |
|
871 |
QCOMPARE(printer.printRange(), QPrinter::PrintRange(!status)); |
|
872 |
} |
|
873 |
{ |
|
874 |
QPrinter printer; |
|
875 |
printer.setOutputFormat(oldFormat); |
|
876 |
QString status = printer.printerName(); |
|
877 |
printer.setOutputFormat(newFormat); |
|
878 |
printer.setOutputFormat(oldFormat); |
|
879 |
QCOMPARE(printer.printerName(), status); |
|
880 |
||
881 |
status = QString::fromLatin1("SuperDuperPrinter"); |
|
882 |
printer.setPrinterName(status); |
|
883 |
printer.setOutputFormat(newFormat); |
|
884 |
QCOMPARE(printer.printerName(), status); |
|
885 |
printer.setOutputFormat(oldFormat); |
|
886 |
QCOMPARE(printer.printerName(), status); |
|
887 |
} |
|
888 |
#ifndef Q_OS_WIN |
|
889 |
{ |
|
890 |
QPrinter printer; |
|
891 |
printer.setOutputFormat(oldFormat); |
|
892 |
QString status = printer.printerSelectionOption(); |
|
893 |
printer.setOutputFormat(newFormat); |
|
894 |
printer.setOutputFormat(oldFormat); |
|
895 |
QCOMPARE(printer.printerSelectionOption(), status); |
|
896 |
||
897 |
status = QString::fromLatin1("Optional option"); |
|
898 |
printer.setPrinterSelectionOption(status); |
|
899 |
printer.setOutputFormat(newFormat); |
|
900 |
QCOMPARE(printer.printerSelectionOption(), status); |
|
901 |
printer.setOutputFormat(oldFormat); |
|
902 |
QCOMPARE(printer.printerSelectionOption(), status); |
|
903 |
} |
|
904 |
#endif |
|
905 |
{ |
|
906 |
QPrinter printer; |
|
907 |
printer.setOutputFormat(oldFormat); |
|
908 |
int status = printer.resolution(); |
|
909 |
printer.setOutputFormat(newFormat); |
|
910 |
printer.setOutputFormat(oldFormat); |
|
911 |
QCOMPARE(printer.resolution(), status); |
|
912 |
||
913 |
printer.setResolution(status-150); |
|
914 |
printer.setOutputFormat(newFormat); |
|
915 |
QCOMPARE(printer.resolution(), status-150); |
|
916 |
printer.setOutputFormat(oldFormat); |
|
917 |
QCOMPARE(printer.resolution(), status-150); |
|
918 |
} |
|
919 |
} |
|
920 |
||
921 |
void tst_QPrinter::errorReporting() |
|
922 |
{ |
|
923 |
QPrinter p; |
|
924 |
p.setOutputFormat(QPrinter::PdfFormat); |
|
925 |
QCOMPARE(p.isValid(), true); |
|
926 |
QPainter painter; |
|
927 |
#ifndef Q_WS_WIN |
|
928 |
// not sure how to choose a never-writable file on windows. But its QFile behavior anyway, so lets rely on it failing elsewhere |
|
929 |
p.setOutputFileName("/foobar/nonwritable.pdf"); |
|
930 |
QCOMPARE(painter.begin(&p), false); // it should check the output file is writable |
|
931 |
#endif |
|
932 |
p.setOutputFileName("test.pdf"); |
|
933 |
QCOMPARE(painter.begin(&p), true); // it should check the output |
|
934 |
QCOMPARE(p.isValid(), true); |
|
935 |
painter.end(); |
|
936 |
} |
|
937 |
||
938 |
void tst_QPrinter::testCustomPageSizes() |
|
939 |
{ |
|
940 |
QPrinter p; |
|
941 |
||
942 |
QSizeF customSize(8.5, 11.0); |
|
943 |
p.setPaperSize(customSize, QPrinter::Inch); |
|
944 |
||
945 |
QSizeF paperSize = p.paperSize(QPrinter::Inch); |
|
946 |
QCOMPARE(paperSize, customSize); |
|
947 |
||
948 |
QPrinter p2(QPrinter::HighResolution); |
|
949 |
p2.setPaperSize(customSize, QPrinter::Inch); |
|
950 |
paperSize = p.paperSize(QPrinter::Inch); |
|
951 |
QCOMPARE(paperSize, customSize); |
|
952 |
} |
|
953 |
||
954 |
void tst_QPrinter::printDialogCompleter() |
|
955 |
{ |
|
956 |
#if defined(QT_NO_COMPLETER) || defined(QT_NO_FILEDIALOG) |
|
957 |
QSKIP("QT_NO_COMPLETER || QT_NO_FILEDIALOG: Auto-complete turned off in QPrinterDialog.", QTest::SkipAll); |
|
958 |
#else |
|
959 |
QPrintDialog dialog; |
|
960 |
dialog.printer()->setOutputFileName("file.pdf"); |
|
961 |
dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile); |
|
962 |
dialog.show(); |
|
963 |
||
964 |
QTest::qWait(100); |
|
965 |
||
966 |
QTest::keyClick(&dialog, Qt::Key_Tab); |
|
967 |
QTest::keyClick(&dialog, 'P'); |
|
968 |
// The test passes if it doesn't crash. |
|
969 |
#endif |
|
970 |
} |
|
971 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
972 |
void tst_QPrinter::testCopyCount() |
0 | 973 |
{ |
974 |
QPrinter p; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
975 |
p.setCopyCount(15); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
976 |
QCOMPARE(p.copyCount(), 15); |
0 | 977 |
} |
978 |
||
979 |
static void printPage(QPainter *painter) |
|
980 |
{ |
|
981 |
painter->setPen(QPen(Qt::black, 4)); |
|
982 |
painter->drawRect(50, 60, 70, 80); |
|
983 |
} |
|
984 |
||
985 |
void tst_QPrinter::taskQTBUG4497_reusePrinterOnDifferentFiles() |
|
986 |
{ |
|
987 |
QPrinter printer; |
|
988 |
{ |
|
989 |
||
990 |
printer.setOutputFileName("out1.ps"); |
|
991 |
QPainter painter(&printer); |
|
992 |
printPage(&painter); |
|
993 |
||
994 |
} |
|
995 |
{ |
|
996 |
||
997 |
printer.setOutputFileName("out2.ps"); |
|
998 |
QPainter painter(&printer); |
|
999 |
printPage(&painter); |
|
1000 |
||
1001 |
} |
|
1002 |
QFile file1("out1.ps"); |
|
1003 |
QVERIFY(file1.open(QIODevice::ReadOnly)); |
|
1004 |
||
1005 |
QFile file2("out2.ps"); |
|
1006 |
QVERIFY(file2.open(QIODevice::ReadOnly)); |
|
1007 |
||
1008 |
QCOMPARE(file1.readAll(), file2.readAll()); |
|
1009 |
} |
|
1010 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1011 |
void tst_QPrinter::testCurrentPage() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1012 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1013 |
QPrinter printer; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1014 |
printer.setFromTo(1, 10); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1015 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1016 |
// Test set print range |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1017 |
printer.setPrintRange(QPrinter::CurrentPage); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1018 |
QCOMPARE(printer.printRange(), QPrinter::CurrentPage); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1019 |
QCOMPARE(printer.fromPage(), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1020 |
QCOMPARE(printer.toPage(), 10); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1021 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1022 |
QPrintDialog dialog(&printer); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1023 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1024 |
// Test default Current Page option to off |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1025 |
QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1026 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1027 |
// Test enable Current Page option |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1028 |
dialog.setOption(QPrintDialog::PrintCurrentPage); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1029 |
QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1030 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1031 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1032 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1033 |
void tst_QPrinter::testPdfTitle() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1034 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1035 |
// Check the document name is represented correctly in produced pdf |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1036 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1037 |
QPainter painter; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1038 |
QPrinter printer; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1039 |
// This string is just the UTF-8 encoding of the string: \()f ø hiragana o |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1040 |
const char title[]={0x5c, 0x28, 0x29, 0x66, 0xc3, 0xb8, 0xe3, 0x81, 0x8a, 0x00}; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1041 |
printer.setOutputFileName("file.pdf"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1042 |
printer.setDocName(QString::fromUtf8(title)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1043 |
painter.begin(&printer); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1044 |
painter.end(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1045 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1046 |
QFile file("file.pdf"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1047 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1048 |
// The we expect the title to appear in the PDF as: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1049 |
// ASCII('\title (') UTF16(\\\(\)f ø hiragana o) ASCII(')'). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1050 |
// which has the following binary representation |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1051 |
const char expected[] = { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1052 |
0x2f, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x20, 0x28, 0xfe, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1053 |
0xff, 0x00, 0x5c, 0x5c, 0x00, 0x5c, 0x28, 0x00, 0x5c, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1054 |
0x29, 0x00, 0x66, 0x00, 0xf8, 0x30, 0x4a, 0x29}; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1055 |
QVERIFY(file.readAll().contains(QByteArray(expected, 26))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1056 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
29
diff
changeset
|
1057 |
|
0 | 1058 |
QTEST_MAIN(tst_QPrinter) |
1059 |
#include "tst_qprinter.moc" |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1060 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1061 |
#else //QT_NO_PRINTER |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1062 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1063 |
QTEST_NOOP_MAIN |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1064 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1065 |
#endif //QT_NO_PRINTER |