From 0fb839ac62fe9feb8700783270d03f1e9ccb3914 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 19 Dec 2014 10:36:46 +0100 Subject: 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 --- .../io/qresourceengine/android_testdata.qrc | 21 +++++++++ .../corelib/io/qresourceengine/qresourceengine.pro | 4 ++ .../io/qresourceengine/tst_qresourceengine.cpp | 54 ++++++++++++++++++---- 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 tests/auto/corelib/io/qresourceengine/android_testdata.qrc (limited to 'tests/auto/corelib/io/qresourceengine') diff --git a/tests/auto/corelib/io/qresourceengine/android_testdata.qrc b/tests/auto/corelib/io/qresourceengine/android_testdata.qrc new file mode 100644 index 0000000000..ad3389ac20 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/android_testdata.qrc @@ -0,0 +1,21 @@ + + + runtime_resource.rcc + parentdir.txt + testqrc/blahblah.txt + testqrc/currentdir.txt + testqrc/currentdir2.txt + testqrc/search_file.txt + testqrc/aliasdir/aliasdir.txt + testqrc/aliasdir/compressme.txt + testqrc/otherdir/otherdir.txt + testqrc/searchpath1/search_file.txt + testqrc/searchpath2/search_file.txt + testqrc/subdir/subdir.txt + testqrc/test/test/test2.txt + testqrc/test/test/test1.txt + testqrc/test/german.txt + testqrc/test/testdir.txt + testqrc/test/testdir2.txt + + diff --git a/tests/auto/corelib/io/qresourceengine/qresourceengine.pro b/tests/auto/corelib/io/qresourceengine/qresourceengine.pro index b7606eb3fc..92d0952b89 100644 --- a/tests/auto/corelib/io/qresourceengine/qresourceengine.pro +++ b/tests/auto/corelib/io/qresourceengine/qresourceengine.pro @@ -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 +} diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 20a5fa2786..5f8b79d2fc 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -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); -- cgit v1.2.3