Changed painting unittests to remove created files after run.
authorKurt Korbatits <kurt.korbatits@nokia.com>
Mon, 23 Jan 2012 00:53:15 +0000 (10:53 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Jan 2012 05:59:09 +0000 (06:59 +0100)
- qpainter cleans up temp files dest.png, expected.png and foo.png
- qpainterpath clean up temp file data
- qprinter cleans up silly, out1.ps, out2.ps, test.pdf and file.pdf

Change-Id: Id434bea0bae5b970355206a250456e4beeca8060
Reviewed-by: Kurt Korbatits <kurt.korbatits@nokia.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
tests/auto/gui/painting/qpainter/tst_qpainter.cpp
tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
tests/auto/gui/painting/qprinter/tst_qprinter.cpp

index 5440d77..4e4e9a9 100644 (file)
@@ -89,6 +89,7 @@ public:
 public slots:
     void init();
     void cleanup();
+    void cleanupTestCase();
 private slots:
     void getSetCheck();
     void drawPixmap_comp_data();
@@ -364,6 +365,13 @@ void tst_QPainter::cleanup()
 {
 }
 
+void tst_QPainter::cleanupTestCase()
+{
+    QFile::remove(QLatin1String("dest.png"));
+    QFile::remove(QLatin1String("expected.png"));
+    QFile::remove(QLatin1String("foo.png"));
+}
+
 static const char* const maskSource_data[] = {
 "16 13 6 1",
 ". c None",
index d745c8e..d30ed86 100644 (file)
@@ -54,7 +54,8 @@ class tst_QPainterPath : public QObject
     Q_OBJECT
 
 public:
-
+public slots:
+    void cleanupTestCase();
 private slots:
     void getSetCheck();
     void swap();
@@ -115,6 +116,11 @@ private slots:
     void lineWithinBounds();
 };
 
+void tst_QPainterPath::cleanupTestCase()
+{
+    QFile::remove(QLatin1String("data"));
+}
+
 // Testing get/set functions
 void tst_QPainterPath::getSetCheck()
 {
index 90a8fd5..e9ad780 100644 (file)
@@ -60,6 +60,23 @@ Q_DECLARE_METATYPE(QRect)
 
 QT_FORWARD_DECLARE_CLASS(QPrinter)
 
+// Helper class to make sure temp files are cleaned up after test complete
+class TempFileCleanup
+{
+public:
+    TempFileCleanup(const QString &file)
+        : m_file(file)
+    {
+    }
+
+    ~TempFileCleanup()
+    {
+        QFile::remove(m_file);
+    }
+private:
+    QString m_file;
+};
+
 class tst_QPrinter : public QObject
 {
     Q_OBJECT
@@ -288,6 +305,7 @@ void tst_QPrinter::testPageRectAndPaperRect()
     QPrinter printer(QPrinter::HighResolution);
     printer.setOrientation(QPrinter::Orientation(orientation));
     printer.setOutputFileName("silly");
+    TempFileCleanup tmpFile("silly");
 
     QRect pageRect = doPaperRect ? printer.paperRect() : printer.pageRect();
     float inchesX = float(pageRect.width()) / float(printer.resolution());
@@ -376,6 +394,7 @@ void tst_QPrinter::testMargins()
 
     if (painter)
         delete painter;
+    QFile::remove("silly");
 }
 
 void tst_QPrinter::testNonExistentPrinter()
@@ -505,6 +524,7 @@ void tst_QPrinter::outputFormatFromSuffix()
     QPrinter p;
     QVERIFY(p.outputFormat() == QPrinter::NativeFormat);
     p.setOutputFileName("test.pdf");
+    TempFileCleanup tmpFile("test.pdf");
     QVERIFY(p.outputFormat() == QPrinter::PdfFormat);
     p.setOutputFileName(QString());
     QVERIFY(p.outputFormat() == QPrinter::NativeFormat);
@@ -865,6 +885,7 @@ void tst_QPrinter::errorReporting()
     QCOMPARE(painter.begin(&p), false); // it should check the output file is writable
 #endif
     p.setOutputFileName("test.pdf");
+    TempFileCleanup tmpFile("test.pdf");
     QCOMPARE(painter.begin(&p), true); // it should check the output
     QCOMPARE(p.isValid(), true);
     painter.end();
@@ -891,6 +912,7 @@ void tst_QPrinter::printDialogCompleter()
 {
     QPrintDialog dialog;
     dialog.printer()->setOutputFileName("file.pdf");
+    TempFileCleanup tmpFile("file.pdf");
     dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile);
     dialog.show();
 
@@ -917,6 +939,9 @@ static void printPage(QPainter *painter)
 
 void tst_QPrinter::taskQTBUG4497_reusePrinterOnDifferentFiles()
 {
+    TempFileCleanup tmpFile1("out1.ps");
+    TempFileCleanup tmpFile2("out2.ps");
+
     QPrinter printer;
     {
 
@@ -978,6 +1003,7 @@ void tst_QPrinter::testPdfTitle()
         painter.begin(&printer);
         painter.end();
     }
+    TempFileCleanup tmpFile("file.pdf");
     QFile file("file.pdf");
     QVERIFY(file.open(QIODevice::ReadOnly));
     // The we expect the title to appear in the PDF as: