QStandardPaths/Unix: restore org and app names in unittests

Some unittests set a custom Organization and Application names and then
clears them. Instead used init() method to "reset" those two names to
the original values before each unittest is run.

Pick-to: 6.5
Change-Id: I359f3911dd50a2aecfd8dde22e2d591adc6e224e
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Ahmad Samir 2023-04-20 12:26:24 +02:00
parent b9786f21b8
commit e320280f61

View File

@ -36,6 +36,7 @@ class tst_qstandardpaths : public QObject
private slots:
void initTestCase();
void dump();
void init();
void testDefaultLocations();
void testCustomLocations();
void enableTestMode();
@ -140,6 +141,16 @@ void tst_qstandardpaths::dump()
}
}
void tst_qstandardpaths::init()
{
// Some unittests set a custom org/app names, restore the original ones
// before each unittest is run
static const QString org = QCoreApplication::organizationName();
static const QString app = QCoreApplication::applicationName();
QCoreApplication::setOrganizationName(org);
QCoreApplication::setApplicationName(app);
}
void tst_qstandardpaths::testDefaultLocations()
{
#ifdef Q_XDG_PLATFORM
@ -308,10 +319,6 @@ void tst_qstandardpaths::testDataLocation()
QCOMPARE(appDataDirs.at(1), QString::fromLatin1("/usr/local/share/Qt/QtTest"));
QCOMPARE(appDataDirs.at(2), QString::fromLatin1("/usr/share/Qt/QtTest"));
#endif
// reset for other tests
QCoreApplication::setOrganizationName(QString());
QCoreApplication::setApplicationName(QString());
}
void tst_qstandardpaths::testAppConfigLocation()
@ -325,9 +332,6 @@ void tst_qstandardpaths::testAppConfigLocation()
QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation), base + "/Qt/tst_qstandardpaths");
QCoreApplication::setApplicationName("QtTest");
QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation), base + "/Qt/QtTest");
// reset for other tests
QCoreApplication::setOrganizationName(QString());
QCoreApplication::setApplicationName(QString());
#endif
}