diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2014-12-19 14:34:46 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> | 2015-01-08 10:06:50 +0100 |
commit | 7ad75cd8ef7e95bba3cfc694b7baffbc445bd2b0 (patch) | |
tree | 632cd658845bc99be1c92957d9a73a3108e558ef /tests/auto/corelib/io/qtemporaryfile | |
parent | 954d355fbcf901587a4dd177fe176cc2131ec4a0 (diff) |
Android: Fix QTemporaryFile tests
Fixed a few instances of files that should be deployed to the
file system. The way we do this on Android is via qrc. We also
need a special case for the resources/test.txt, because
QFINDTESTDATA will find this in qrc, but that's not the one
we are looking for.
Change-Id: I7097e8b7795b3a8fd483adad090208f295478412
Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'tests/auto/corelib/io/qtemporaryfile')
3 files changed, 48 insertions, 9 deletions
diff --git a/tests/auto/corelib/io/qtemporaryfile/android_testdata.qrc b/tests/auto/corelib/io/qtemporaryfile/android_testdata.qrc new file mode 100644 index 0000000000..f30290c262 --- /dev/null +++ b/tests/auto/corelib/io/qtemporaryfile/android_testdata.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/android_testdata"> + <file>tst_qtemporaryfile.cpp</file> + <file>resources/test.txt</file> + </qresource> +</RCC> diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro index 8a91340e5f..c16a729ad0 100644 --- a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro +++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro @@ -5,4 +5,8 @@ QT = core testlib SOURCES = tst_qtemporaryfile.cpp TESTDATA += tst_qtemporaryfile.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -RESOURCES += qtemporaryfile.qrc
\ No newline at end of file +RESOURCES += qtemporaryfile.qrc + +android:!android-no-sdk { + RESOURCES += android_testdata.qrc +} diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index a08a0ae777..29a3c4e18a 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -92,6 +92,24 @@ void tst_QTemporaryFile::initTestCase() // For QTBUG_4796 QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); QCoreApplication::setApplicationName("tst_qtemporaryfile"); + +#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())); + } + } + } +#endif } void tst_QTemporaryFile::cleanupTestCase() @@ -253,20 +271,21 @@ void tst_QTemporaryFile::autoRemove() QVERIFY(!QFile::exists(fileName)); } +struct ChdirOnReturn +{ + ChdirOnReturn(const QString& d) : dir(d) {} + ~ChdirOnReturn() { + QDir::setCurrent(dir); + } + QString dir; +}; + void tst_QTemporaryFile::nonWritableCurrentDir() { #ifdef Q_OS_UNIX if (::geteuid() == 0) QSKIP("not valid running this test as root"); - struct ChdirOnReturn - { - ChdirOnReturn(const QString& d) : dir(d) {} - ~ChdirOnReturn() { - QDir::setCurrent(dir); - } - QString dir; - }; ChdirOnReturn cor(QDir::currentPath()); #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) @@ -443,6 +462,12 @@ void tst_QTemporaryFile::rename() void tst_QTemporaryFile::renameFdLeak() { #ifdef Q_OS_UNIX + +# if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + ChdirOnReturn cor(QDir::currentPath()); + QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); +# endif + const QByteArray sourceFile = QFile::encodeName(QFINDTESTDATA(__FILE__)); QVERIFY(!sourceFile.isEmpty()); // Test this on Unix only @@ -646,7 +671,11 @@ void tst_QTemporaryFile::createNativeFile_data() QTest::addColumn<bool>("valid"); QTest::addColumn<QByteArray>("content"); +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + const QString nativeFilePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/resources/test.txt"); +#else const QString nativeFilePath = QFINDTESTDATA("resources/test.txt"); +#endif QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); |