From f7bead1dd6e6801f6136cd02ef0506b97e3bb95f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 20 Sep 2023 11:32:02 -0700 Subject: [PATCH] Q{Temporary,}File: make QStandardPaths use test mode The moveToTrash tests, on XDG platforms, would be trashing to ~/.local/share/Trash. Unlike Windows and Apple systems, the XDG trash spec creates two files and these tests weren't deleting both of them, so we had a slow increase of left-over files in ~/.local/share/Trash/info. Cleaning up ~/.qttest is left as an exercise for the users. For example, $ cat ~/.config/user-tmpfiles.d/qttest.conf #Type Path Mode User Group Age Argument e %h/.qttest 0700 - - 1w Pick-to: 6.5 6.2 Change-Id: I9d43e5b91eb142d6945cfffd1786aeff91d34fde Reviewed-by: Volker Hilsheimer (cherry picked from commit 772ad60425866d895cbd76cfb478893ec8496505) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 9 ++++++--- .../corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 6ea699bc24a..7a5c1f6fd16 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -13,12 +13,13 @@ #include #include #include -#include -#include -#include #include +#include #include #include +#include +#include +#include #include #include @@ -428,6 +429,8 @@ void tst_QFile::cleanup() tst_QFile::tst_QFile() : m_oldDir(QDir::currentPath()) { + QStandardPaths::setTestModeEnabled(true); + QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); } static QByteArray msgOpenFailed(QIODevice::OpenMode om, const QFile &file) diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 42194fe7e5d..3940aabf772 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -4,13 +4,14 @@ #include #include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include #include @@ -81,6 +82,9 @@ private: void tst_QTemporaryFile::initTestCase() { + QStandardPaths::setTestModeEnabled(true); + QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); + QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString())); m_previousCurrent = QDir::currentPath(); QVERIFY(QDir::setCurrent(m_temporaryDir.path()));