tests/auto/qprinter/tst_qprinter.cpp
changeset 30 5dc02b23752f
parent 29 b72c6db6890b
child 33 3e2da88830cd
--- a/tests/auto/qprinter/tst_qprinter.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/tests/auto/qprinter/tst_qprinter.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -64,13 +64,11 @@
 
 Q_DECLARE_METATYPE(QRect)
 
-QT_FORWARD_DECLARE_CLASS(QPrinter)
+
 
 //TESTED_CLASS=
 //TESTED_FILES=
 
-#ifndef QT_NO_PRINTER
-
 class tst_QPrinter : public QObject
 {
     Q_OBJECT
@@ -108,9 +106,11 @@
     void testCustomPageSizes();
     void printDialogCompleter();
 
-    void testActualNumCopies();
+    void testCopyCount();
+    void testCurrentPage();
 
     void taskQTBUG4497_reusePrinterOnDifferentFiles();
+    void testPdfTitle();
 
 private:
 };
@@ -217,6 +217,7 @@
 
 tst_QPrinter::~tst_QPrinter()
 {
+
 }
 
 // initTestCase will be executed once before the first testfunction is executed.
@@ -417,7 +418,7 @@
     printer.setFullPage(fullpage);
     printer.setPageSize((QPrinter::PageSize)pagesize);
     if (withPainter)
-	painter = new QPainter(&printer);
+        painter = new QPainter(&printer);
 
 #ifdef QT3_SUPPORT
     Q3PaintDeviceMetrics metrics(&printer);
@@ -456,7 +457,7 @@
     printer.pageSize();
     printer.orientation();
     printer.fullPage();
-    printer.setNumCopies(1);
+    printer.setCopyCount(1);
     printer.printerName();
 
     // nor metrics
@@ -967,11 +968,11 @@
 #endif
 }
 
-void tst_QPrinter::testActualNumCopies()
+void tst_QPrinter::testCopyCount()
 {
     QPrinter p;
-    p.setNumCopies(15);
-    QCOMPARE(p.actualNumCopies(), 15);
+    p.setCopyCount(15);
+    QCOMPARE(p.copyCount(), 15);
 }
 
 static void printPage(QPainter *painter)
@@ -1006,11 +1007,52 @@
     QCOMPARE(file1.readAll(), file2.readAll());
 }
 
+void tst_QPrinter::testCurrentPage()
+{
+    QPrinter printer;
+    printer.setFromTo(1, 10);
+
+    // Test set print range
+    printer.setPrintRange(QPrinter::CurrentPage);
+    QCOMPARE(printer.printRange(), QPrinter::CurrentPage);
+    QCOMPARE(printer.fromPage(), 1);
+    QCOMPARE(printer.toPage(), 10);
+
+    QPrintDialog dialog(&printer);
+
+    // Test default Current Page option to off
+    QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), false);
+
+    // Test enable Current Page option
+    dialog.setOption(QPrintDialog::PrintCurrentPage);
+    QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), true);
+
+}
+
+void tst_QPrinter::testPdfTitle()
+{
+    // Check the document name is represented correctly in produced pdf
+    {
+        QPainter painter;
+        QPrinter printer;
+        // This string is just the UTF-8 encoding of the string: \()f ø hiragana o
+        const char title[]={0x5c, 0x28, 0x29, 0x66, 0xc3, 0xb8, 0xe3, 0x81, 0x8a, 0x00};
+        printer.setOutputFileName("file.pdf");
+        printer.setDocName(QString::fromUtf8(title));
+        painter.begin(&printer);
+        painter.end();
+    }
+    QFile file("file.pdf");
+    QVERIFY(file.open(QIODevice::ReadOnly));
+    // The we expect the title to appear in the PDF as:
+    // ASCII('\title (') UTF16(\\\(\)f ø hiragana o) ASCII(')').
+    // which has the following binary representation
+    const char expected[] = {
+        0x2f, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x20, 0x28, 0xfe,
+        0xff, 0x00, 0x5c, 0x5c, 0x00, 0x5c, 0x28, 0x00, 0x5c,
+        0x29, 0x00, 0x66, 0x00, 0xf8, 0x30, 0x4a, 0x29};
+    QVERIFY(file.readAll().contains(QByteArray(expected, 26)));
+}
+
 QTEST_MAIN(tst_QPrinter)
 #include "tst_qprinter.moc"
-
-#else //QT_NO_PRINTER
-
-QTEST_NOOP_MAIN
-
-#endif //QT_NO_PRINTER