Install plasma theme into local XDG_DATA_DIR for icon test
Summary: Relevant code is moved from dialognativetest into a header for sharing Test Plan: Unit test Reviewers: #plasma Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D22732
This commit is contained in:
parent
31cd4f8d8e
commit
08a6a4a7cd
@ -18,39 +18,15 @@
|
|||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
|
|
||||||
#include "dialognativetest.h"
|
#include "dialognativetest.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
|
|
||||||
void copyPath(const QString &src, const QString &dst)
|
|
||||||
{
|
|
||||||
QDir dir(src);
|
|
||||||
Q_ASSERT(dir.exists());
|
|
||||||
|
|
||||||
foreach (const auto &d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
|
||||||
QString dst_path = dst + QLatin1Char('/') + d;
|
|
||||||
dir.mkpath(dst_path);
|
|
||||||
copyPath(src + QLatin1Char('/') + d, dst_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const auto &f, dir.entryList(QDir::Files)) {
|
|
||||||
QFile::copy(src + QLatin1Char('/') + f, dst + QLatin1Char('/') + f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogNativeTest::initTestCase()
|
void DialogNativeTest::initTestCase()
|
||||||
{
|
{
|
||||||
QStandardPaths::setTestModeEnabled(true);
|
QStandardPaths::setTestModeEnabled(true);
|
||||||
{
|
Plasma::TestUtils::installPlasmaTheme();
|
||||||
const auto qttestPath = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).constFirst();
|
|
||||||
Q_ASSERT(!qttestPath.isEmpty());
|
|
||||||
QDir themePath(qttestPath + QLatin1String("/plasma/desktoptheme/default"));
|
|
||||||
|
|
||||||
auto data = QFINDTESTDATA("../src/desktoptheme/breeze/metadata.desktop");
|
|
||||||
QFileInfo f(data);
|
|
||||||
QVERIFY(f.dir().mkpath(themePath.path()));
|
|
||||||
|
|
||||||
copyPath(f.dir().filePath("default.gzipped"), themePath.path());
|
|
||||||
QFile::copy(f.dir().filePath("metadata.desktop"), themePath.filePath("metadata.desktop"));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_cacheDir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
m_cacheDir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||||
m_cacheDir.removeRecursively();
|
m_cacheDir.removeRecursively();
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
#include "plasma/theme.h"
|
#include "plasma/theme.h"
|
||||||
#include "plasma/svg.h"
|
#include "plasma/svg.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
static bool imageIsEmpty(const QImage &img)
|
static bool imageIsEmpty(const QImage &img)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < img.width(); ++i) {
|
for (int i = 0; i < img.width(); ++i) {
|
||||||
@ -47,20 +49,8 @@ static bool imageIsEmpty(const QImage &img)
|
|||||||
|
|
||||||
void IconItemTest::initTestCase()
|
void IconItemTest::initTestCase()
|
||||||
{
|
{
|
||||||
if (qgetenv("XDG_DATA_DIRS").isEmpty()) {
|
Plasma::TestUtils::installPlasmaTheme();
|
||||||
QWARN("\n"
|
qputenv("XDG_DATA_DIRS", qgetenv("XDG_DATA_DIRS") + ":" + QFINDTESTDATA("data").toLocal8Bit());
|
||||||
" !!!\n"
|
|
||||||
" Switching QStandardPaths into testing mode.\n"
|
|
||||||
" Make sure xdg data can be found or set XDG_DATA_DIRS.\n"
|
|
||||||
" !!!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// make our theme in search path
|
|
||||||
qputenv("XDG_DATA_DIRS",
|
|
||||||
qgetenv("XDG_DATA_DIRS") + ":" + QFINDTESTDATA("data").toLocal8Bit());
|
|
||||||
|
|
||||||
// set default icon theme to test-theme
|
|
||||||
QStandardPaths::setTestModeEnabled(true);
|
|
||||||
|
|
||||||
QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
|
QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
|
||||||
|
|
||||||
|
58
autotests/utils.h
Normal file
58
autotests/utils.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2019 Aleix Pol <apol@kde.org>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
namespace Plasma {
|
||||||
|
namespace TestUtils {
|
||||||
|
|
||||||
|
static void copyPath(const QString &src, const QString &dst) {
|
||||||
|
QDir dir(src);
|
||||||
|
Q_ASSERT(dir.exists());
|
||||||
|
|
||||||
|
foreach (const auto &d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
|
QString dst_path = dst + QLatin1Char('/') + d;
|
||||||
|
dir.mkpath(dst_path);
|
||||||
|
copyPath(src + QLatin1Char('/') + d, dst_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const auto &f, dir.entryList(QDir::Files)) {
|
||||||
|
QFile::copy(src + QLatin1Char('/') + f, dst + QLatin1Char('/') + f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void installPlasmaTheme() {
|
||||||
|
QStandardPaths::setTestModeEnabled(true);
|
||||||
|
const auto qttestPath = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).constFirst();
|
||||||
|
Q_ASSERT(!qttestPath.isEmpty());
|
||||||
|
QDir themePath(qttestPath + QLatin1String("/plasma/desktoptheme/default"));
|
||||||
|
|
||||||
|
auto data = QFINDTESTDATA("../src/desktoptheme/breeze/metadata.desktop");
|
||||||
|
QFileInfo f(data);
|
||||||
|
QVERIFY(f.dir().mkpath(themePath.path()));
|
||||||
|
|
||||||
|
copyPath(f.dir().filePath("default.gzipped"), themePath.path());
|
||||||
|
QFile::copy(f.dir().filePath("metadata.desktop"), themePath.filePath("metadata.desktop"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} //TestUtils
|
||||||
|
} //Plasma
|
Loading…
Reference in New Issue
Block a user