Changed qimagewriter unittest to work from install directory.

- Changed to use QFINDTESTDATA and TESTDATA
- skip testing permissions if test run as root user

Change-Id: I5b308789202b01bdd0d630af65775ae23bf0cc4c
Reviewed-by: Kurt Korbatits  <kurt.korbatits@nokia.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
This commit is contained in:
Kurt Korbatits 2012-01-16 11:23:30 +10:00 committed by Qt by Nokia
parent 7beeb932fd
commit b93ce4d78c
2 changed files with 25 additions and 17 deletions

View File

@ -7,11 +7,4 @@ MOC_DIR=tmp
win32-msvc:QMAKE_CXXFLAGS -= -Zm200
win32-msvc:QMAKE_CXXFLAGS += -Zm800
wince*: {
addFiles.files = images\\*.*
addFiles.path = images
DEPLOYMENT += addFiles
DEFINES += SRCDIR=\\\".\\\"
} else {
DEFINES += SRCDIR=\\\"$$PWD\\\"
}
TESTDATA += images/*

View File

@ -71,6 +71,7 @@ public:
public slots:
void init();
void initTestCase();
void cleanup();
private slots:
@ -100,10 +101,10 @@ private slots:
void resolution();
void saveToTemporaryFile();
private:
QString prefix;
};
static const QLatin1String prefix(SRCDIR "/images/");
static void initializePadding(QImage *image)
{
int effectiveBytesPerLine = (image->width() * image->depth() + 7) / 8;
@ -115,6 +116,13 @@ static void initializePadding(QImage *image)
}
}
void tst_QImageWriter::initTestCase()
{
prefix = QFINDTESTDATA("images/");
if (prefix.isEmpty())
QFAIL("Can't find images directory!");
}
// Testing get/set functions
void tst_QImageWriter::getSetCheck()
{
@ -217,15 +225,22 @@ void tst_QImageWriter::writeImage()
}
{
// Shouldn't be able to write to read-only file
QFile sourceFile(prefix + "gen-" + fileName);
QFile::Permissions permissions = sourceFile.permissions();
QVERIFY(sourceFile.setPermissions(QFile::ReadOwner | QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther));
bool skip = false;
#if defined(Q_OS_UNIX)
if (::geteuid() == 0)
skip = true;
#endif
if (!skip) {
// Shouldn't be able to write to read-only file
QFile sourceFile(prefix + "gen-" + fileName);
QFile::Permissions permissions = sourceFile.permissions();
QVERIFY(sourceFile.setPermissions(QFile::ReadOwner | QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther));
QImageWriter writer(prefix + "gen-" + fileName, format);
QVERIFY(!writer.write(image));
QImageWriter writer(prefix + "gen-" + fileName, format);
QVERIFY(!writer.write(image));
QVERIFY(sourceFile.setPermissions(permissions));
QVERIFY(sourceFile.setPermissions(permissions));
}
}
QImage image2;