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 <bogdan@kde.org>bb10
parent
999321fecb
commit
0b16f42565
|
|
@ -0,0 +1,44 @@
|
|||
<RCC>
|
||||
<qresource prefix="/android_testdata">
|
||||
<file>tst_qdir.cpp</file>
|
||||
<file>entrylist/file</file>
|
||||
<file>entrylist/directory/dummy</file>
|
||||
<file>searchdir/subdir1/picker.png</file>
|
||||
<file>searchdir/subdir2/picker.png</file>
|
||||
<file>testData/empty</file>
|
||||
<file>testdir/dir/tmp/empty</file>
|
||||
<file>testdir/dir/qdir.pro</file>
|
||||
<file>testdir/dir/qrc_qdir.cpp</file>
|
||||
<file>testdir/dir/tst_qdir.cpp</file>
|
||||
<file>testdir/spaces/foo. bar</file>
|
||||
<file>testdir/spaces/foo.bar</file>
|
||||
<file>types/a</file>
|
||||
<file>types/a.a</file>
|
||||
<file>types/a.b</file>
|
||||
<file>types/a.c</file>
|
||||
<file>types/b</file>
|
||||
<file>types/b.a</file>
|
||||
<file>types/b.b</file>
|
||||
<file>types/b.c</file>
|
||||
<file>types/c</file>
|
||||
<file>types/c.a</file>
|
||||
<file>types/c.b</file>
|
||||
<file>types/c.c</file>
|
||||
<file>types/d/dummy</file>
|
||||
<file>types/d.a/dummy</file>
|
||||
<file>types/d.c/dummy</file>
|
||||
<file>types/d.b/dummy</file>
|
||||
<file>types/e/dummy</file>
|
||||
<file>types/e.a/dummy</file>
|
||||
<file>types/e.c/dummy</file>
|
||||
<file>types/f/dummy</file>
|
||||
<file>types/f.a/dummy</file>
|
||||
<file>types/f.b/dummy</file>
|
||||
<file>types/f.c/dummy</file>
|
||||
<file>types/e.b/dummy</file>
|
||||
<file>resources/entryList/file1.data</file>
|
||||
<file>resources/entryList/file2.data</file>
|
||||
<file>resources/entryList/file3.data</file>
|
||||
<file>resources/entryList/file4.nothing</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue