Android: Fix QFileInfo tests

Since there's no way to deploy files directly to the file file
system on Android, we put them in a qrc file and extract them
on startup.

Change-Id: I6a42aa5e0372bfd9fb2f7ccfea964c9c3c2e45d8
Reviewed-by: BogDan Vatra <bogdan@kde.org>
bb10
Eskil Abrahamsen Blomfeldt 2014-12-18 13:05:22 +01:00
parent 0dd7bd0c7a
commit 5681ae74e3
3 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/android_testdata">
<file>resources/file1</file>
<file>resources/file1.ext1</file>
<file>resources/file1.ext1.ext2</file>
<file>tst_qfileinfo.cpp</file>
</qresource>
</RCC>

View File

@ -8,3 +8,7 @@ TESTDATA += qfileinfo.qrc qfileinfo.pro tst_qfileinfo.cpp resources/file1 resour
win32*:!wince*:!winrt:LIBS += -ladvapi32 -lnetapi32
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
android:!android-no-sdk: {
RESOURCES += android_testdata.qrc
}

View File

@ -272,9 +272,32 @@ private:
void tst_QFileInfo::initTestCase()
{
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
QString dataPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
QString resourceSourcePath = QStringLiteral(":/android_testdata");
QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
QFileInfo fileInfo = it.fileInfo();
if (!fileInfo.isDir()) {
QString destination = dataPath + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length());
QFileInfo destinationFileInfo(destination);
if (!destinationFileInfo.exists()) {
QDir().mkpath(destinationFileInfo.path());
if (!QFile::copy(fileInfo.filePath(), destination))
qWarning("Failed to copy %s", qPrintable(fileInfo.filePath()));
}
}
}
m_sourceFile = dataPath + QStringLiteral("/tst_qfileinfo.cpp");
m_resourcesDir = dataPath + QStringLiteral("/resources");
#else
m_sourceFile = QFINDTESTDATA("tst_qfileinfo.cpp");
QVERIFY(!m_sourceFile.isEmpty());
m_resourcesDir = QFINDTESTDATA("resources");
#endif
QVERIFY(!m_sourceFile.isEmpty());
QVERIFY(!m_resourcesDir.isEmpty());
QVERIFY(m_dir.isValid());
QVERIFY(QDir::setCurrent(m_dir.path()));