Android: Fix QResourceEngine tests

The test expects all the files to reside in the file system,
both for loading the runtime resources and for comparisons.
Since we can't deploy directly to the file system on Android,
we go via qrc and extract the files on startup instead.

Change-Id: I17ff8985cb17dbfc45f0fb692ca46558bb5c5cdc
Reviewed-by: BogDan Vatra <bogdan@kde.org>
bb10
Eskil Abrahamsen Blomfeldt 2014-12-19 10:36:46 +01:00
parent a07120d496
commit 0fb839ac62
3 changed files with 71 additions and 8 deletions

View File

@ -0,0 +1,21 @@
<RCC>
<qresource prefix="/android_testdata">
<file>runtime_resource.rcc</file>
<file>parentdir.txt</file>
<file>testqrc/blahblah.txt</file>
<file>testqrc/currentdir.txt</file>
<file>testqrc/currentdir2.txt</file>
<file>testqrc/search_file.txt</file>
<file>testqrc/aliasdir/aliasdir.txt</file>
<file>testqrc/aliasdir/compressme.txt</file>
<file>testqrc/otherdir/otherdir.txt</file>
<file>testqrc/searchpath1/search_file.txt</file>
<file>testqrc/searchpath2/search_file.txt</file>
<file>testqrc/subdir/subdir.txt</file>
<file>testqrc/test/test/test2.txt</file>
<file>testqrc/test/test/test1.txt</file>
<file>testqrc/test/german.txt</file>
<file>testqrc/test/testdir.txt</file>
<file>testqrc/test/testdir2.txt</file>
</qresource>
</RCC>

View File

@ -16,3 +16,7 @@ TESTDATA += \
testqrc/*
GENERATED_TESTDATA = $${runtime_resource.target}
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
android:!android-no-sdk {
RESOURCES += android_testdata.qrc
}

View File

@ -40,7 +40,13 @@ class tst_QResourceEngine: public QObject
Q_OBJECT
public:
tst_QResourceEngine() : m_runtimeResourceRcc(QFINDTESTDATA("runtime_resource.rcc")) {}
tst_QResourceEngine()
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
: m_runtimeResourceRcc(QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/runtime_resource.rcc")).absoluteFilePath())
#else
: m_runtimeResourceRcc(QFINDTESTDATA("runtime_resource.rcc"))
#endif
{}
private slots:
void initTestCase();
@ -62,6 +68,29 @@ private:
void tst_QResourceEngine::initTestCase()
{
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
QString sourcePath(QStringLiteral(":/android_testdata/"));
QString dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
QDirIterator it(sourcePath, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
QFileInfo fileInfo = it.fileInfo();
if (!fileInfo.isDir()) {
QString destination(dataPath + QLatin1Char('/') + fileInfo.filePath().mid(sourcePath.length()));
QFileInfo destinationFileInfo(destination);
if (!destinationFileInfo.exists()) {
QVERIFY(QDir().mkpath(destinationFileInfo.path()));
QVERIFY(QFile::copy(fileInfo.filePath(), destination));
QVERIFY(QFileInfo(destination).exists());
}
}
}
QVERIFY(QDir::setCurrent(dataPath));
#endif
QVERIFY(!m_runtimeResourceRcc.isEmpty());
QVERIFY(QResource::registerResource(m_runtimeResourceRcc));
QVERIFY(QResource::registerResource(m_runtimeResourceRcc, "/secondary_root/"));
@ -85,16 +114,25 @@ void tst_QResourceEngine::checkStructure_data()
QFileInfo info;
QStringList rootContents;
rootContents << QLatin1String("aliasdir")
<< QLatin1String("otherdir")
<< QLatin1String("qt-project.org")
<< QLatin1String("runtime_resource")
<< QLatin1String("searchpath1")
<< QLatin1String("searchpath2")
<< QLatin1String("secondary_root")
<< QLatin1String("test")
<< QLatin1String("withoutslashes");
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
rootContents.insert(1, QLatin1String("android_testdata"));
#endif
QTest::newRow("root dir") << QString(":/")
<< QString()
<< (QStringList() << "search_file.txt")
<< (QStringList() << QLatin1String("aliasdir") << QLatin1String("otherdir")
<< QLatin1String("qt-project.org")
<< QLatin1String("runtime_resource")
<< QLatin1String("searchpath1") << QLatin1String("searchpath2")
<< QLatin1String("secondary_root")
<< QLatin1String("test")
<< QLatin1String("withoutslashes"))
<< rootContents
<< QLocale::c()
<< qlonglong(0);