tst_QFileSystemModel: don't expect ~/Documents to exist

For me, this test failed because I don't have a Documents folder in my
home directory, even though that's what's returned from QStandardPaths
as the first DocumentsLocation.

Fix by falling back on the home directory if documentPaths.front()
does not exist.

Change-Id: I483f62f3b4b43d055c74774a7058a4aa420849b1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
bb10
Marc Mutz 2013-11-16 22:07:01 +01:00 committed by The Qt Project
parent 6533a736a7
commit 885bd1d0e5
1 changed files with 8 additions and 1 deletions

View File

@ -212,7 +212,14 @@ void tst_QFileSystemModel::rootPath()
QString oldRootPath = model->rootPath();
const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
QVERIFY(!documentPaths.isEmpty());
const QString documentPath = documentPaths.front();
QString documentPath = documentPaths.front();
// In particular on Linux, ~/Documents (the first
// DocumentsLocation) may not exist, so choose ~ in that case:
if (!QFile::exists(documentPath)) {
documentPath = QDir::homePath();
qWarning("%s: first documentPath \"%s\" does not exist. Using ~ (\"%s\") instead.",
Q_FUNC_INFO, qPrintable(documentPaths.front()), qPrintable(documentPath));
}
root = model->setRootPath(documentPath);
QTRY_VERIFY(model->rowCount(root) >= 0);