From 0b16f425652c0e804ddac9cbca2d0063cfdad55e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 18 Dec 2014 11:58:27 +0100 Subject: [PATCH] Android: Fix QDir tests There's no way to install files automatically into the file system on Android, so to test QDir on the file system, we have to bundle the files in qrc and then copy them into the file system on startup. This adds some complexity, but at least it will detect regressions. We also need to make sure the current directory is the same as the data path, since the test assumes this, and /usr/ does not exist on Android, so we have to use a different path to find the root path. Change-Id: I18d79b5ed99a0afff573beb30c61745c403f8991 Reviewed-by: BogDan Vatra --- .../auto/corelib/io/qdir/android_testdata.qrc | 44 +++++++++++++++++++ tests/auto/corelib/io/qdir/qdir.pro | 4 ++ tests/auto/corelib/io/qdir/tst_qdir.cpp | 29 ++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/auto/corelib/io/qdir/android_testdata.qrc diff --git a/tests/auto/corelib/io/qdir/android_testdata.qrc b/tests/auto/corelib/io/qdir/android_testdata.qrc new file mode 100644 index 0000000000..52cf4da330 --- /dev/null +++ b/tests/auto/corelib/io/qdir/android_testdata.qrc @@ -0,0 +1,44 @@ + + + tst_qdir.cpp + entrylist/file + entrylist/directory/dummy + searchdir/subdir1/picker.png + searchdir/subdir2/picker.png + testData/empty + testdir/dir/tmp/empty + testdir/dir/qdir.pro + testdir/dir/qrc_qdir.cpp + testdir/dir/tst_qdir.cpp + testdir/spaces/foo. bar + testdir/spaces/foo.bar + types/a + types/a.a + types/a.b + types/a.c + types/b + types/b.a + types/b.b + types/b.c + types/c + types/c.a + types/c.b + types/c.c + types/d/dummy + types/d.a/dummy + types/d.c/dummy + types/d.b/dummy + types/e/dummy + types/e.a/dummy + types/e.c/dummy + types/f/dummy + types/f.a/dummy + types/f.b/dummy + types/f.c/dummy + types/e.b/dummy + resources/entryList/file1.data + resources/entryList/file2.data + resources/entryList/file3.data + resources/entryList/file4.nothing + + diff --git a/tests/auto/corelib/io/qdir/qdir.pro b/tests/auto/corelib/io/qdir/qdir.pro index e2b25866df..d3e954bd32 100644 --- a/tests/auto/corelib/io/qdir/qdir.pro +++ b/tests/auto/corelib/io/qdir/qdir.pro @@ -6,3 +6,7 @@ RESOURCES += qdir.qrc TESTDATA += testdir testData searchdir resources entrylist types tst_qdir.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +android:!android-no-sdk { + RESOURCES += android_testdata.qrc +} diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 49e3264617..484130f163 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -214,8 +214,35 @@ private: Q_DECLARE_METATYPE(tst_QDir::UncHandling) tst_QDir::tst_QDir() +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + : m_dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) +#else : m_dataPath(QFileInfo(QFINDTESTDATA("testData")).absolutePath()) +#endif { +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + QString resourceSourcePath = QStringLiteral(":/android_testdata/"); + QDirIterator it(resourceSourcePath, QDirIterator::Subdirectories); + while (it.hasNext()) { + it.next(); + + QFileInfo fileInfo = it.fileInfo(); + + if (!fileInfo.isDir()) { + QString destination = m_dataPath + QLatin1Char('/') + fileInfo.filePath().mid(resourceSourcePath.length()); + QFileInfo destinationFileInfo(destination); + if (!destinationFileInfo.exists()) { + QDir().mkpath(destinationFileInfo.path()); + if (!QFile::copy(fileInfo.filePath(), destination)) + qWarning("Failed to copy %s", qPrintable(fileInfo.filePath())); + } + } + + } + + if (!QDir::setCurrent(m_dataPath)) + qWarning("Couldn't set current path to %s", qPrintable(m_dataPath)); +#endif } void tst_QDir::init() @@ -2028,6 +2055,8 @@ void tst_QDir::equalityOperator_data() //need a path in the root directory that is unlikely to be a symbolic link. #if defined (Q_OS_WIN) QString pathinroot("c:/windows/.."); +#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + QString pathinroot("/system/.."); #else QString pathinroot("/usr/.."); #endif