diff --git a/autotests/dialognativetest.cpp b/autotests/dialognativetest.cpp --- a/autotests/dialognativetest.cpp +++ b/autotests/dialognativetest.cpp @@ -18,39 +18,15 @@ *********************************************************************************/ #include "dialognativetest.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); - } -} +#include "utils.h" + +#include 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 --- 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 @@ 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 --- /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