Android: Fix QTranslator tests

Bundle test data in qrc on Android. Extract it, as the tests
expect to find it in the file system.

Change-Id: I251eca3c23141a608b1cbac5ee0b7164c068f9b4
Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2014-12-19 15:01:38 +01:00
parent af32727362
commit 75f0578124
3 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/android_testdata">
<file>hellotr_la.qm</file>
<file>msgfmt_from_po.qm</file>
<file>dependencies_la.qm</file>
</qresource>
</RCC>

View File

@ -4,4 +4,6 @@ QT = core testlib
SOURCES = tst_qtranslator.cpp
RESOURCES += qtranslator.qrc
TESTDATA += hellotr_la.qm msgfmt_from_po.qm
android:!android-no-sdk: RESOURCES += android_testdata.qrc
else: TESTDATA += hellotr_la.qm msgfmt_from_po.qm

View File

@ -68,6 +68,26 @@ tst_QTranslator::tst_QTranslator()
void tst_QTranslator::initTestCase()
{
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
QString sourceDir(":/android_testdata/");
QDirIterator it(sourceDir, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
QFileInfo sourceFileInfo = it.fileInfo();
if (!sourceFileInfo.isDir()) {
QFileInfo destinationFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + sourceFileInfo.filePath().mid(sourceDir.length()));
if (!destinationFileInfo.exists()) {
QVERIFY(QDir().mkpath(destinationFileInfo.path()));
QVERIFY(QFile::copy(sourceFileInfo.filePath(), destinationFileInfo.filePath()));
}
}
}
QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
#endif
// chdir into the directory containing our testdata,
// to make the code simpler (load testdata via relative paths)
QString testdata_dir = QFileInfo(QFINDTESTDATA("hellotr_la.qm")).absolutePath();