tst_qtranslator: Simplify extraction of test data

This makes it easier to further extend the test. The overhead this
causes is negligible.

Change-Id: I42941879f55337268bb2914e122a5f573ab7e6f9
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
(cherry picked from commit 841ce1f938219cb975099a28b720abeb95eea19d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Kai Köhne 2021-07-13 17:48:46 +02:00 committed by Qt Cherry-pick Bot
parent 8df7212325
commit e90398e3be
4 changed files with 5 additions and 45 deletions

View File

@ -11,8 +11,10 @@ qt_internal_add_test(tst_qtranslator
# Resources:
set(qtranslator_resource_files
"dependencies_la.qm"
"hellotr_empty.qm"
"hellotr_la.qm"
"msgfmt_from_po.qm"
)
qt_internal_add_resource(tst_qtranslator "qtranslator"

View File

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

View File

@ -1,6 +0,0 @@
<RCC>
<qresource prefix="/tst_qtranslator">
<file>hellotr_la.qm</file>
<file>hellotr_empty.qm</file>
</qresource>
</RCC>

View File

@ -73,38 +73,10 @@ tst_QTranslator::tst_QTranslator()
void tst_QTranslator::initTestCase()
{
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
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)
#if 0
// ### TODO: Use this for all platforms in 5.7
dataDir = QEXTRACTTESTDATA(QStringLiteral("/"));
dataDir = QEXTRACTTESTDATA(QStringLiteral("/tst_qtranslator"));
QVERIFY2(!dataDir.isNull(), qPrintable("Could not extract test data"));
QVERIFY2(QDir::setCurrent(dataDir->path()), qPrintable("Could not chdir to " + dataDir->path()));
#else
QString testdata_dir = QFileInfo(QFINDTESTDATA("hellotr_la.qm")).absolutePath();
QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir));
#endif
QVERIFY2(QDir::setCurrent(dataDir->path()),
qPrintable("Could not chdir to " + dataDir->path()));
}
bool tst_QTranslator::eventFilter(QObject *, QEvent *event)