From 08a6a4a7cd537a897d243472fe0501110febb214 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 24 Jul 2019 23:43:38 +0100 Subject: [PATCH] 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 --- autotests/dialognativetest.cpp | 32 +++---------------- autotests/iconitemtest.cpp | 18 +++-------- autotests/utils.h | 58 ++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 autotests/utils.h diff --git a/autotests/dialognativetest.cpp b/autotests/dialognativetest.cpp index 1055bdd2f..79d23dd75 100644 --- a/autotests/dialognativetest.cpp +++ b/autotests/dialognativetest.cpp @@ -18,39 +18,15 @@ *********************************************************************************/ #include "dialognativetest.h" + +#include "utils.h" + #include -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() { 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")); - } + Plasma::TestUtils::installPlasmaTheme(); m_cacheDir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); m_cacheDir.removeRecursively(); diff --git a/autotests/iconitemtest.cpp b/autotests/iconitemtest.cpp index f8c9d2765..8373a24d1 100644 --- a/autotests/iconitemtest.cpp +++ b/autotests/iconitemtest.cpp @@ -33,6 +33,8 @@ #include "plasma/theme.h" #include "plasma/svg.h" +#include "utils.h" + static bool imageIsEmpty(const QImage &img) { for (int i = 0; i < img.width(); ++i) { @@ -47,20 +49,8 @@ static bool imageIsEmpty(const QImage &img) void IconItemTest::initTestCase() { - if (qgetenv("XDG_DATA_DIRS").isEmpty()) { - QWARN("\n" - " !!!\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); + Plasma::TestUtils::installPlasmaTheme(); + qputenv("XDG_DATA_DIRS", qgetenv("XDG_DATA_DIRS") + ":" + QFINDTESTDATA("data").toLocal8Bit()); QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); diff --git a/autotests/utils.h b/autotests/utils.h new file mode 100644 index 000000000..0ccee7fed --- /dev/null +++ b/autotests/utils.h @@ -0,0 +1,58 @@ +/* + Copyright (C) 2019 Aleix Pol + + 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 +#include +#include +#include + +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