Merge branch 'mart/coronaautotest'

REVIEW:119270
This commit is contained in:
Marco Martin 2014-07-14 20:48:31 +02:00
commit 427acdb373
7 changed files with 308 additions and 1 deletions

View File

@ -4,8 +4,11 @@ set_package_properties(Qt5Test PROPERTIES PURPOSE "Required for tests")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
include(ECMMarkAsTest)
include(ECMAddTests)
find_package(KF5CoreAddons REQUIRED)
find_package(KF5XmlGui REQUIRED)
find_package(Qt5Widgets REQUIRED)
# add_definitions( -DKDESRCDIR=${CMAKE_CURRENT_SOURCE_DIR} )
@ -35,7 +38,13 @@ PLASMA_UNIT_TESTS(
)
add_executable(storagetest storagetest.cpp ../src/plasma/private/storage.cpp ../src/plasma/private/storagethread.cpp)
target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons )
target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons)
set(coronatest_srcs coronatest.cpp)
qt5_add_resources(coronatest_srcs coronatestresources.qrc)
ecm_add_test(${coronatest_srcs} TEST_NAME coronatest LINK_LIBRARIES Qt5::Gui Qt5::Widgets Qt5::Test KF5::KIOCore KF5::Plasma KF5::CoreAddons KF5::XmlGui)
add_test(plasma-storagetest storagetest)
ecm_mark_as_test(storagetest)

194
autotests/coronatest.cpp Normal file
View File

@ -0,0 +1,194 @@
/********************************************************************************
* 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 "coronatest.h"
#include <ksycoca.h>
#include <kactioncollection.h>
#include <QStandardPaths>
#include <QAction>
#include <QApplication>
Plasma::Applet *SimpleLoader::internalLoadApplet(const QString &name, uint appletId,
const QVariantList &args)
{
if (name == "simpleapplet") {
return new SimpleApplet();
} else {
return 0;
}
}
SimpleCorona::SimpleCorona(QObject *parent)
: Plasma::Corona(parent)
{
Plasma::PluginLoader::setPluginLoader(new SimpleLoader);
}
SimpleCorona::~SimpleCorona()
{}
QRect SimpleCorona::screenGeometry(int screen) const
{
//completely arbitrary, still not tested
return QRect(100*screen, 100, 100, 100);
}
SimpleApplet::SimpleApplet(QObject *parent , const QString &serviceId, uint appletId)
: Plasma::Applet(parent, serviceId, appletId)
{
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
//updateConstraints(Plasma::Types::UiReadyConstraint);
m_timer.setSingleShot(true);
m_timer.setInterval(qrand() % ((500 + 1) - 100) + 100);
m_timer.start();
connect(&m_timer, &QTimer::timeout, [=]() {
updateConstraints(Plasma::Types::UiReadyConstraint);
});
}
static void runKBuildSycoca()
{
QProcess proc;
const QString kbuildsycoca = QStandardPaths::findExecutable(KBUILDSYCOCA_EXENAME);
QVERIFY(!kbuildsycoca.isEmpty());
QStringList args;
args << "--testmode";
proc.setProcessChannelMode(QProcess::MergedChannels); // silence kbuildsycoca output
proc.start(kbuildsycoca, args);
QSignalSpy spy(KSycoca::self(), SIGNAL(databaseChanged(QStringList)));
QVERIFY(spy.wait(10000));
proc.waitForFinished();
QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
}
void CoronaTest::initTestCase()
{
if (!KSycoca::isAvailable()) {
runKBuildSycoca();
}
QStandardPaths::setTestModeEnabled(true);
m_corona = new SimpleCorona;
m_configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
m_configDir.removeRecursively();
QVERIFY(m_configDir.mkpath("."));
QVERIFY(QFile::copy(QStringLiteral(":/plasma-test-appletsrc"), m_configDir.filePath(QStringLiteral("plasma-test-appletsrc"))));
}
void CoronaTest::cleanupTestCase()
{
m_configDir.removeRecursively();
delete m_corona;
}
void CoronaTest::restore()
{
m_corona->loadLayout("plasma-test-appletsrc");
QCOMPARE(m_corona->containments().count(), 1);
QCOMPARE(m_corona->containments().first()->applets().count(), 2);
}
void CoronaTest::startupCompletion()
{
QVERIFY(!m_corona->isStartupCompleted());
QVERIFY(!m_corona->containments().first()->isUiReady());
QSignalSpy spy(m_corona, SIGNAL(startupCompleted()));
QVERIFY(spy.wait(1000));
QVERIFY(m_corona->isStartupCompleted());
QVERIFY(m_corona->containments().first()->isUiReady());
}
void CoronaTest::addRemoveApplets()
{
m_corona->containments().first()->createApplet("invalid");
QCOMPARE(m_corona->containments().first()->applets().count(), 3);
//remove action present
QVERIFY(m_corona->containments().first()->applets().first()->actions()->action("remove"));
//kill an applet
m_corona->containments().first()->applets().first()->actions()->action("remove")->trigger();
QSignalSpy spy(m_corona->containments().first()->applets().first(), SIGNAL(destroyed()));
QVERIFY(spy.wait(1000));
QCOMPARE(m_corona->containments().first()->applets().count(), 2);
}
//this test has to be the last, since systemimmutability
//can't be programmatically unlocked
void CoronaTest::immutability()
{
//immutability
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
m_corona->setImmutability(Plasma::Types::UserImmutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::UserImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::UserImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::UserImmutable);
}
}
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::Mutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::Mutable);
}
}
m_corona->setImmutability(Plasma::Types::SystemImmutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
}
}
//can't unlock systemimmutable
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Containment *cont : m_corona->containments()) {
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
for (Plasma::Applet *app : cont->applets()) {
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
}
}
}
QTEST_MAIN(CoronaTest)

78
autotests/coronatest.h Normal file
View File

@ -0,0 +1,78 @@
/******************************************************************************
* 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 CORONATEST_H
#define CORONATEST_H
#include <QtTest/QtTest>
#include <QTimer>
#include "plasma/corona.h"
#include "plasma/pluginloader.h"
class SimpleLoader : public Plasma::PluginLoader
{
protected:
virtual Plasma::Applet *internalLoadApplet(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList());
};
class SimpleCorona : public Plasma::Corona
{
Q_OBJECT
public:
explicit SimpleCorona(QObject * parent = 0);
~SimpleCorona();
QRect screenGeometry(int) const;
};
class SimpleApplet : public Plasma::Applet
{
Q_OBJECT
public:
explicit SimpleApplet(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
private:
QTimer m_timer;
};
class CoronaTest : public QObject
{
Q_OBJECT
public Q_SLOTS:
void initTestCase();
void cleanupTestCase();
private Q_SLOTS:
void restore();
void startupCompletion();
void addRemoveApplets();
void immutability();
private:
SimpleCorona *m_corona;
QDir m_configDir;
};
#endif

View File

@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>plasma-test-appletsrc</file>
</qresource>
</RCC>

View File

@ -0,0 +1,18 @@
[Containments][1]
formfactor=0
immutability=1
lastScreen=0
location=0
plugin=simpleapplet
[Containments][1][Applets][2]
immutability=1
plugin=invalid
[Containments][1][Applets][3]
immutability=1
plugin=simpleapplet
[General]
immutability=1

View File

@ -442,6 +442,8 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi
delete applet;
}
applet = containment = new Containment(q, 0, id);
//if it's a dummy containment, just say its ui is ready, not blocking the corona
applet->updateConstraints(Plasma::Types::UiReadyConstraint);
// we want to provide something and don't care about the failure to launch
containment->setFormFactor(Plasma::Types::Planar);

View File

@ -210,6 +210,7 @@ Applet *ContainmentPrivate::createApplet(const QString &name, const QVariantList
qWarning() << "Applet" << name << "could not be loaded.";
applet = new Applet(0, QString(), id);
applet->setLaunchErrorMessage(i18n("Could not find requested component: %1", name));
applet->updateConstraints(Plasma::Types::UiReadyConstraint);
}
q->addApplet(applet);