From 772ad60425866d895cbd76cfb478893ec8496505 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.6 6.5 6.2 Change-Id: I9d43e5b91eb142d6945cfffd1786aeff91d34fde Reviewed-by: Volker Hilsheimer --- 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 911e373c4e..68138df3fb 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 @@ -433,6 +434,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 95f1661758..0191c9a3e7 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 @@ -80,6 +81,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()));