104 void valuePreservation(); |
104 void valuePreservation(); |
105 void errorReporting(); |
105 void errorReporting(); |
106 void testCustomPageSizes(); |
106 void testCustomPageSizes(); |
107 void printDialogCompleter(); |
107 void printDialogCompleter(); |
108 |
108 |
109 void testActualNumCopies(); |
109 void testCopyCount(); |
|
110 void testCurrentPage(); |
110 |
111 |
111 void taskQTBUG4497_reusePrinterOnDifferentFiles(); |
112 void taskQTBUG4497_reusePrinterOnDifferentFiles(); |
|
113 void testPdfTitle(); |
112 |
114 |
113 private: |
115 private: |
114 }; |
116 }; |
115 |
117 |
116 // Testing get/set functions |
118 // Testing get/set functions |
414 printer.setOutputFileName("silly"); |
416 printer.setOutputFileName("silly"); |
415 printer.setOrientation((QPrinter::Orientation)orientation); |
417 printer.setOrientation((QPrinter::Orientation)orientation); |
416 printer.setFullPage(fullpage); |
418 printer.setFullPage(fullpage); |
417 printer.setPageSize((QPrinter::PageSize)pagesize); |
419 printer.setPageSize((QPrinter::PageSize)pagesize); |
418 if (withPainter) |
420 if (withPainter) |
419 painter = new QPainter(&printer); |
421 painter = new QPainter(&printer); |
420 |
422 |
421 #ifdef QT3_SUPPORT |
423 #ifdef QT3_SUPPORT |
422 Q3PaintDeviceMetrics metrics(&printer); |
424 Q3PaintDeviceMetrics metrics(&printer); |
423 int pwidth = metrics.width(); |
425 int pwidth = metrics.width(); |
424 int pheight = metrics.height(); |
426 int pheight = metrics.height(); |
453 printer.setOrientation(QPrinter::Portrait); |
455 printer.setOrientation(QPrinter::Portrait); |
454 printer.setFullPage(true); |
456 printer.setFullPage(true); |
455 printer.pageSize(); |
457 printer.pageSize(); |
456 printer.orientation(); |
458 printer.orientation(); |
457 printer.fullPage(); |
459 printer.fullPage(); |
458 printer.setNumCopies(1); |
460 printer.setCopyCount(1); |
459 printer.printerName(); |
461 printer.printerName(); |
460 |
462 |
461 // nor metrics |
463 // nor metrics |
462 QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmWidth), 0); |
464 QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmWidth), 0); |
463 QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmHeight), 0); |
465 QCOMPARE(printer.printEngine()->metric(QPaintDevice::PdmHeight), 0); |
964 QTest::keyClick(&dialog, 'P'); |
966 QTest::keyClick(&dialog, 'P'); |
965 // The test passes if it doesn't crash. |
967 // The test passes if it doesn't crash. |
966 #endif |
968 #endif |
967 } |
969 } |
968 |
970 |
969 void tst_QPrinter::testActualNumCopies() |
971 void tst_QPrinter::testCopyCount() |
970 { |
972 { |
971 QPrinter p; |
973 QPrinter p; |
972 p.setNumCopies(15); |
974 p.setCopyCount(15); |
973 QCOMPARE(p.actualNumCopies(), 15); |
975 QCOMPARE(p.copyCount(), 15); |
974 } |
976 } |
975 |
977 |
976 static void printPage(QPainter *painter) |
978 static void printPage(QPainter *painter) |
977 { |
979 { |
978 painter->setPen(QPen(Qt::black, 4)); |
980 painter->setPen(QPen(Qt::black, 4)); |
1003 QVERIFY(file2.open(QIODevice::ReadOnly)); |
1005 QVERIFY(file2.open(QIODevice::ReadOnly)); |
1004 |
1006 |
1005 QCOMPARE(file1.readAll(), file2.readAll()); |
1007 QCOMPARE(file1.readAll(), file2.readAll()); |
1006 } |
1008 } |
1007 |
1009 |
|
1010 void tst_QPrinter::testCurrentPage() |
|
1011 { |
|
1012 QPrinter printer; |
|
1013 printer.setFromTo(1, 10); |
|
1014 |
|
1015 // Test set print range |
|
1016 printer.setPrintRange(QPrinter::CurrentPage); |
|
1017 QCOMPARE(printer.printRange(), QPrinter::CurrentPage); |
|
1018 QCOMPARE(printer.fromPage(), 1); |
|
1019 QCOMPARE(printer.toPage(), 10); |
|
1020 |
|
1021 QPrintDialog dialog(&printer); |
|
1022 |
|
1023 // Test default Current Page option to off |
|
1024 QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), false); |
|
1025 |
|
1026 // Test enable Current Page option |
|
1027 dialog.setOption(QPrintDialog::PrintCurrentPage); |
|
1028 QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), true); |
|
1029 |
|
1030 } |
|
1031 |
|
1032 void tst_QPrinter::testPdfTitle() |
|
1033 { |
|
1034 // Check the document name is represented correctly in produced pdf |
|
1035 { |
|
1036 QPainter painter; |
|
1037 QPrinter printer; |
|
1038 // This string is just the UTF-8 encoding of the string: \()f ø hiragana o |
|
1039 const char title[]={0x5c, 0x28, 0x29, 0x66, 0xc3, 0xb8, 0xe3, 0x81, 0x8a, 0x00}; |
|
1040 printer.setOutputFileName("file.pdf"); |
|
1041 printer.setDocName(QString::fromUtf8(title)); |
|
1042 painter.begin(&printer); |
|
1043 painter.end(); |
|
1044 } |
|
1045 QFile file("file.pdf"); |
|
1046 QVERIFY(file.open(QIODevice::ReadOnly)); |
|
1047 // The we expect the title to appear in the PDF as: |
|
1048 // ASCII('\title (') UTF16(\\\(\)f ø hiragana o) ASCII(')'). |
|
1049 // which has the following binary representation |
|
1050 const char expected[] = { |
|
1051 0x2f, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x20, 0x28, 0xfe, |
|
1052 0xff, 0x00, 0x5c, 0x5c, 0x00, 0x5c, 0x28, 0x00, 0x5c, |
|
1053 0x29, 0x00, 0x66, 0x00, 0xf8, 0x30, 0x4a, 0x29}; |
|
1054 QVERIFY(file.readAll().contains(QByteArray(expected, 26))); |
|
1055 } |
|
1056 |
1008 QTEST_MAIN(tst_QPrinter) |
1057 QTEST_MAIN(tst_QPrinter) |
1009 #include "tst_qprinter.moc" |
1058 #include "tst_qprinter.moc" |