summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-06 16:36:37 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-07 14:27:09 +0200
commita033c23ddffed6b9bff3e7be68d513a7962c3b5e (patch)
tree99b6d15bca0711c8030c4abb62b26d0e6ba577a5 /tests/auto/corelib
parentef0287d589cd1a73655fa89b274145e318839299 (diff)
QFile::moveToTrash: work with relative file paths on Windows
The system APIs expect an absolute "display name" of the file path, so make it absolute. The test was overly tolerant in accepting failure, as a QStorageInfo initialized with a file path that doesn't exist is invalid, and thus always different from the QStorageInfo of the home directory. Fix the test to compare only valid QStorageInfo objects, and postpone the check until the file we want to move has been created. [ChangeLog][QtCore][QFile] moveToTrash supports relative file paths on Windows Change-Id: I94c8cd40c60fde469e38f76a98f867f20c6a0b15 Fixes: QTBUG-84015 Pick-to: 5.15 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 2e4ed2fba1..624ab39188 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -3714,13 +3714,6 @@ void tst_QFile::moveToTrash()
QFETCH(bool, create);
QFETCH(bool, result);
- /* This test makes assumptions about the file system layout
- which might be wrong - moveToTrash may fail if the file lives
- on a file system that is different from the home file system, and
- has no .Trash directory.
- */
- const bool mayFail = QStorageInfo(source) != QStorageInfo(QDir::home());
-
#if defined(Q_OS_WINRT)
QSKIP("WinRT does not have a trash", SkipAll);
#endif
@@ -3749,9 +3742,20 @@ void tst_QFile::moveToTrash()
sourceFile.remove();
}
};
+
+ ensureFile(source, create);
+
+ /* This test makes assumptions about the file system layout
+ which might be wrong - moveToTrash may fail if the file lives
+ on a file system that is different from the home file system, and
+ has no .Trash directory.
+ */
+ const QStorageInfo sourceStorage(source);
+ const bool mayFail = sourceStorage.isValid()
+ && QStorageInfo(source) != QStorageInfo(QDir::home());
+
// non-static version
{
- ensureFile(source, create);
QFile sourceFile(source);
const bool success = sourceFile.moveToTrash();