diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-11-24 08:40:32 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-11-24 15:30:04 +0000 |
commit | 1e8863e39dfc72422e76dae214d35268685eb52a (patch) | |
tree | d01dda8b115e3317d02e8947cf96c5cc23e71d35 /tests/auto/gui/image/qimagereader | |
parent | 09b64aa9d338e6e1926bcf45494272565f5fa6bc (diff) |
tst_QImageReader: Fix file handling.
Use a QTemporaryFile in readFromFileAfterJunk() instead writing
to the current directory which might not have write permission.
Enclose each call to QFile::open() in QVERIFY2() with error message.
Change-Id: I3c5da31c6681a2396cee473cafe7d92c5c220de3
Reviewed-by: aavit <eirik.aavitsland@theqtcompany.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'tests/auto/gui/image/qimagereader')
-rw-r--r-- | tests/auto/gui/image/qimagereader/tst_qimagereader.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index d1e4883cf9..86dd8c4daf 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -36,7 +36,6 @@ #include <QBuffer> #include <QDebug> -#include <QFile> #include <QImage> #include <QImageReader> #include <QImageWriter> @@ -46,6 +45,7 @@ #include <QTcpServer> #include <QTimer> #include <QTemporaryDir> +#include <QTemporaryFile> #include <algorithm> @@ -53,6 +53,22 @@ typedef QMap<QString, QString> QStringMap; typedef QList<int> QIntList; Q_DECLARE_METATYPE(QImage::Format) +static QByteArray msgFileOpenWriteFailed(const QFile &file) +{ + const QString result = QLatin1String("Cannot open \"") + + QDir::toNativeSeparators(file.fileName()) + + QLatin1String("\" for writing: ") + file.errorString(); + return result.toLocal8Bit(); +} + +static QByteArray msgFileOpenReadFailed(const QFile &file) +{ + const QString result = QLatin1String("Cannot open \"") + + QDir::toNativeSeparators(file.fileName()) + + QLatin1String("\" for reading: ") + file.errorString(); + return result.toLocal8Bit(); +} + class tst_QImageReader : public QObject { Q_OBJECT @@ -1051,7 +1067,7 @@ void tst_QImageReader::readFromDevice() const QString imageFileName = prefix + fileName; QImage expectedImage(imageFileName, format); QFile file(imageFileName); - QVERIFY(file.open(QFile::ReadOnly)); + QVERIFY2(file.open(QFile::ReadOnly), msgFileOpenReadFailed(file).constData()); QByteArray imageData = file.readAll(); QVERIFY(!imageData.isEmpty()); { @@ -1129,12 +1145,11 @@ void tst_QImageReader::readFromFileAfterJunk() SKIP_IF_UNSUPPORTED(format); - QFile::remove("junk"); - QFile junkFile("junk"); - QVERIFY(junkFile.open(QFile::WriteOnly)); + QTemporaryFile junkFile(m_temporaryDir.path() + QLatin1String("/junkXXXXXX")); + QVERIFY2(junkFile.open(), msgFileOpenWriteFailed(junkFile).constData()); QFile imageFile(prefix + fileName); - QVERIFY(imageFile.open(QFile::ReadOnly)); + QVERIFY2(imageFile.open(QFile::ReadOnly), msgFileOpenReadFailed(imageFile).constData()); QByteArray imageData = imageFile.readAll(); QVERIFY(!imageData.isNull()); @@ -1155,7 +1170,7 @@ void tst_QImageReader::readFromFileAfterJunk() } } junkFile.close(); - junkFile.open(QFile::ReadOnly); + QVERIFY2(junkFile.open(), msgFileOpenReadFailed(junkFile).constData()); for (int i = 0; i < iterations; ++i) { QByteArray ole = junkFile.read(9); @@ -1205,7 +1220,7 @@ void tst_QImageReader::devicePosition() QVERIFY(!expected.isNull()); QFile imageFile(prefix + fileName); - QVERIFY(imageFile.open(QFile::ReadOnly)); + QVERIFY2(imageFile.open(QFile::ReadOnly), msgFileOpenReadFailed(imageFile).constData()); QByteArray imageData = imageFile.readAll(); QVERIFY(!imageData.isNull()); int imageDataSize = imageData.size(); |