add an autotest for fallback

correct a couple of problems the test catched
This commit is contained in:
Marco Martin 2014-09-01 15:51:05 +02:00
parent 55a6095138
commit 5ceb8d1197
7 changed files with 149 additions and 3 deletions

View File

@ -37,6 +37,7 @@ MACRO(PLASMA_UNIT_TESTS)
ENDMACRO(PLASMA_UNIT_TESTS)
PLASMA_UNIT_TESTS(
fallbackpackagetest
packagestructuretest
packageurlinterceptortest
pluginloadertest

View File

@ -0,0 +1,7 @@
import QtQuick 2.0
Rectangle {
id: root
color: "darkblue"
}

View File

@ -0,0 +1,15 @@
[Desktop Entry]
Encoding=UTF-8
Keywords=
Name=Test Fallback Package
Type=Service
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPLv2+
X-KDE-PluginInfo-Name=org.kde.testfallbackpackage
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-Plasma-MainScript=ui/main.qml

View File

@ -0,0 +1,7 @@
import QtQuick 2.0
Rectangle {
id: root
color: "darkblue"
}

View File

@ -0,0 +1,68 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* Copyright 2014 Marco Martin <mart@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 "fallbackpackagetest.h"
#include <QDebug>
#include "packagestructure.h"
#include "pluginloader.h"
void FallbackPackageTest::initTestCase()
{
m_packagePath = QFINDTESTDATA("data/testpackage");
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
m_pkg.setPath(m_packagePath);
m_fallPackagePath = QFINDTESTDATA("data/testfallbackpackage");
m_fallPkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
m_fallPkg.setPath(m_fallPackagePath);
}
void FallbackPackageTest::beforeFallback()
{
QVERIFY(m_pkg.hasValidStructure());
QVERIFY(m_fallPkg.hasValidStructure());
QVERIFY(!m_pkg.filePath("ui", "otherfile.qml").isEmpty());
QVERIFY(m_fallPkg.filePath("ui", "otherfile.qml").isEmpty());
}
void FallbackPackageTest::afterFallback()
{
m_fallPkg.setFallbackPackage(m_pkg);
QVERIFY(!m_fallPkg.filePath("ui", "otherfile.qml").isEmpty());
QCOMPARE(m_pkg.filePath("ui", "otherfile.qml"), m_fallPkg.filePath("ui", "otherfile.qml"));
QVERIFY(m_pkg.filePath("mainscript") != m_fallPkg.filePath("mainscript"));
}
void FallbackPackageTest::cycle()
{
m_pkg.setFallbackPackage(m_fallPkg);
m_fallPkg.setFallbackPackage(m_pkg);
//The cycle should have been detected and filePath should take a not infinite tiume
QCOMPARE(m_pkg.filePath("ui", "otherfile.qml"), m_fallPkg.filePath("ui", "otherfile.qml"));
}
QTEST_MAIN(FallbackPackageTest)

View File

@ -0,0 +1,46 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* Copyright 2014 Marco Martin <mart@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. *
*******************************************************************************/
#ifndef FALLBACKPACKAGETEST_H
#include <QtTest/QtTest>
#include "plasma/package.h"
class FallbackPackageTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void beforeFallback();
void afterFallback();
void cycle();
private:
Plasma::Package m_pkg;
Plasma::Package m_fallPkg;
QString m_packagePath;
QString m_fallPackagePath;
};
#endif

View File

@ -198,7 +198,7 @@ void Package::setFallbackPackage(const Plasma::Package &package)
return;
}
(*d->fallbackPackage) = package;
d->fallbackPackage = new Package(package);
}
Plasma::Package Package::fallbackPackage() const
@ -819,7 +819,9 @@ PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs)
}
structure = rhs.structure;
if (rhs.fallbackPackage) {
(*fallbackPackage) = (*rhs.fallbackPackage);
}
path = rhs.path;
contentsPrefixPaths = rhs.contentsPrefixPaths;
servicePrefix = rhs.servicePrefix;
@ -923,7 +925,7 @@ bool PackagePrivate::hasCycle(const Plasma::Package &package)
while (fastPackage && fastPackage->d->fallbackPackage) {
//consider two packages the same if they have the same metadata
if ((fastPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->metadata() == slowPackage->metadata()) ||
(fastPackage->d->fallbackPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata() == slowPackage->metadata())) {
(fastPackage->d->fallbackPackage->d->fallbackPackage && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata() == slowPackage->metadata())) {
return true;
}
fastPackage = fastPackage->d->fallbackPackage->d->fallbackPackage;