summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2014-12-19 14:34:46 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2015-01-08 10:06:50 +0100
commit7ad75cd8ef7e95bba3cfc694b7baffbc445bd2b0 (patch)
tree632cd658845bc99be1c92957d9a73a3108e558ef /tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
parent954d355fbcf901587a4dd177fe176cc2131ec4a0 (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/tst_qtemporaryfile.cpp')
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp45
1 files changed, 37 insertions, 8 deletions
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();