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>bb10
parent
09b64aa9d3
commit
1e8863e39d
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue