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 <volker.hilsheimer@qt.io>
This commit is contained in:
Thiago Macieira 2023-09-20 11:32:02 -07:00
parent 201045a1fd
commit 772ad60425
2 changed files with 13 additions and 6 deletions

View File

@ -13,12 +13,13 @@
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QRandomGenerator>
#include <QTemporaryDir>
#include <QTemporaryFile>
#include <QOperatingSystemVersion>
#include <QRandomGenerator>
#include <QStorageInfo>
#include <QScopeGuard>
#include <QStandardPaths>
#include <QTemporaryDir>
#include <QTemporaryFile>
#include <private/qabstractfileengine_p.h>
#include <private/qfsfileengine_p.h>
@ -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)

View File

@ -4,13 +4,14 @@
#include <QTest>
#include <qcoreapplication.h>
#include <qstring.h>
#include <qtemporarydir.h>
#include <qtemporaryfile.h>
#include <qfile.h>
#include <qdatetime.h>
#include <qdir.h>
#include <qset.h>
#include <qstandardpaths.h>
#include <qstring.h>
#include <qtemporarydir.h>
#include <qtemporaryfile.h>
#include <QtTest/private/qtesthelpers_p.h>
@ -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()));