2014-07-11 22:01:56 +02:00
|
|
|
/********************************************************************************
|
2014-07-14 18:03:37 +02:00
|
|
|
* Copyright 2014 Marco Martin <mart@kde.org> *
|
2014-07-11 22:01:56 +02:00
|
|
|
* *
|
|
|
|
* 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>
|
2014-07-14 14:22:36 +02:00
|
|
|
#include <kactioncollection.h>
|
2014-07-11 22:01:56 +02:00
|
|
|
#include <QStandardPaths>
|
2014-07-14 14:22:36 +02:00
|
|
|
#include <QAction>
|
2014-07-11 22:01:56 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
2014-07-14 11:04:48 +02:00
|
|
|
Plasma::Applet *SimpleLoader::internalLoadApplet(const QString &name, uint appletId,
|
|
|
|
const QVariantList &args)
|
2014-07-11 22:01:56 +02:00
|
|
|
{
|
2014-09-26 17:03:45 +02:00
|
|
|
Q_UNUSED(args)
|
2016-02-29 00:08:05 +01:00
|
|
|
if (name == QLatin1String("simpleapplet")) {
|
2018-07-02 00:16:21 +02:00
|
|
|
return new SimpleApplet(nullptr, QString(), appletId);
|
2016-02-29 00:08:05 +01:00
|
|
|
} else if (name == QLatin1String("simplecontainment")) {
|
2018-07-02 00:16:21 +02:00
|
|
|
return new SimpleContainment(nullptr, QString(), appletId);
|
2016-02-29 00:08:05 +01:00
|
|
|
} else if (name == QLatin1String("simplenoscreencontainment")) {
|
2018-07-02 00:16:21 +02:00
|
|
|
return new SimpleNoScreenContainment(nullptr, QString(), appletId);
|
2014-07-14 14:22:36 +02:00
|
|
|
} else {
|
2018-07-02 00:16:21 +02:00
|
|
|
return nullptr;
|
2014-07-14 14:22:36 +02:00
|
|
|
}
|
2014-07-14 11:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleCorona::SimpleCorona(QObject *parent)
|
|
|
|
: Plasma::Corona(parent)
|
|
|
|
{
|
|
|
|
Plasma::PluginLoader::setPluginLoader(new SimpleLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleCorona::~SimpleCorona()
|
|
|
|
{}
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
|
|
|
|
QRect SimpleCorona::screenGeometry(int screen) const
|
|
|
|
{
|
|
|
|
//completely arbitrary, still not tested
|
|
|
|
return QRect(100*screen, 100, 100, 100);
|
|
|
|
}
|
|
|
|
|
2014-09-13 13:55:32 +02:00
|
|
|
int SimpleCorona::screenForContainment(const Plasma::Containment *c) const
|
|
|
|
{
|
|
|
|
if (qobject_cast<const SimpleNoScreenContainment *>(c)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-14 11:04:48 +02:00
|
|
|
SimpleApplet::SimpleApplet(QObject *parent , const QString &serviceId, uint appletId)
|
|
|
|
: Plasma::Applet(parent, serviceId, appletId)
|
|
|
|
{
|
2014-07-14 11:23:22 +02:00
|
|
|
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);
|
|
|
|
});
|
2014-07-14 11:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-15 10:16:10 +02:00
|
|
|
SimpleContainment::SimpleContainment(QObject *parent , const QString &serviceId, uint appletId)
|
|
|
|
: Plasma::Containment(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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-13 13:55:32 +02:00
|
|
|
SimpleNoScreenContainment::SimpleNoScreenContainment(QObject *parent , const QString &serviceId, uint appletId)
|
|
|
|
: Plasma::Containment(parent, serviceId, appletId)
|
|
|
|
{
|
|
|
|
//This containment will *never* be isUiReady()
|
|
|
|
}
|
2014-07-14 11:04:48 +02:00
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
static void runKBuildSycoca()
|
|
|
|
{
|
|
|
|
QProcess proc;
|
2016-02-29 00:08:05 +01:00
|
|
|
const QString kbuildsycoca = QStandardPaths::findExecutable(QStringLiteral(KBUILDSYCOCA_EXENAME));
|
2014-07-11 22:01:56 +02:00
|
|
|
QVERIFY(!kbuildsycoca.isEmpty());
|
|
|
|
QStringList args;
|
2016-02-29 00:08:05 +01:00
|
|
|
args << QStringLiteral("--testmode");
|
2014-07-11 22:01:56 +02:00
|
|
|
proc.setProcessChannelMode(QProcess::MergedChannels); // silence kbuildsycoca output
|
|
|
|
proc.start(kbuildsycoca, args);
|
|
|
|
|
2014-07-14 18:23:21 +02:00
|
|
|
QSignalSpy spy(KSycoca::self(), SIGNAL(databaseChanged(QStringList)));
|
|
|
|
QVERIFY(spy.wait(10000));
|
2014-07-11 22:01:56 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QVERIFY(m_configDir.mkpath(QStringLiteral(".")));
|
2014-07-11 22:01:56 +02:00
|
|
|
|
|
|
|
QVERIFY(QFile::copy(QStringLiteral(":/plasma-test-appletsrc"), m_configDir.filePath(QStringLiteral("plasma-test-appletsrc"))));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaTest::cleanupTestCase()
|
|
|
|
{
|
|
|
|
m_configDir.removeRecursively();
|
2014-07-14 18:07:58 +02:00
|
|
|
delete m_corona;
|
2014-07-11 22:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaTest::restore()
|
|
|
|
{
|
2016-02-29 00:08:05 +01:00
|
|
|
m_corona->loadLayout(QStringLiteral("plasma-test-appletsrc"));
|
2014-09-13 13:55:32 +02:00
|
|
|
QCOMPARE(m_corona->containments().count(), 3);
|
2014-09-15 15:40:15 +02:00
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (auto cont, m_corona->containments()) {
|
2014-09-13 13:55:32 +02:00
|
|
|
switch (cont->id()) {
|
|
|
|
case 1:
|
|
|
|
QCOMPARE(cont->applets().count(), 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
QCOMPARE(cont->applets().count(), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-15 15:40:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CoronaTest::checkOrder()
|
|
|
|
{
|
|
|
|
QCOMPARE(m_corona->containments().count(), 3);
|
|
|
|
|
|
|
|
//check containments order
|
2016-02-29 00:08:05 +01:00
|
|
|
QCOMPARE(m_corona->containments().at(0)->id(), (uint)1);
|
|
|
|
QCOMPARE(m_corona->containments().at(1)->id(), (uint)4);
|
|
|
|
QCOMPARE(m_corona->containments().at(2)->id(), (uint)5);
|
2014-09-15 15:40:15 +02:00
|
|
|
|
2014-09-15 17:55:36 +02:00
|
|
|
//check applets order
|
2016-02-29 00:08:05 +01:00
|
|
|
QCOMPARE(m_corona->containments().at(0)->applets().count(), 2);
|
|
|
|
QCOMPARE(m_corona->containments().at(0)->applets().at(0)->id(), (uint)2);
|
|
|
|
QCOMPARE(m_corona->containments().at(0)->applets().at(1)->id(), (uint)3);
|
2014-07-11 22:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaTest::startupCompletion()
|
|
|
|
{
|
2014-07-14 11:23:22 +02:00
|
|
|
QVERIFY(!m_corona->isStartupCompleted());
|
2016-02-29 00:08:05 +01:00
|
|
|
QVERIFY(!m_corona->containments().at(0)->isUiReady());
|
2014-07-14 11:23:22 +02:00
|
|
|
|
|
|
|
QSignalSpy spy(m_corona, SIGNAL(startupCompleted()));
|
|
|
|
QVERIFY(spy.wait(1000));
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
QVERIFY(m_corona->isStartupCompleted());
|
2016-02-29 00:08:05 +01:00
|
|
|
QVERIFY(m_corona->containments().at(0)->isUiReady());
|
2014-07-11 22:01:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 14:22:36 +02:00
|
|
|
void CoronaTest::addRemoveApplets()
|
|
|
|
{
|
2016-02-29 00:08:05 +01:00
|
|
|
m_corona->containments().at(0)->createApplet(QStringLiteral("invalid"));
|
|
|
|
QCOMPARE(m_corona->containments().at(0)->applets().count(), 3);
|
2014-07-14 14:22:36 +02:00
|
|
|
|
|
|
|
//remove action present
|
2016-02-29 00:08:05 +01:00
|
|
|
QVERIFY(m_corona->containments().at(0)->applets().at(0)->actions()->action(QStringLiteral("remove")));
|
2014-07-14 14:22:36 +02:00
|
|
|
//kill an applet
|
2016-02-29 00:08:05 +01:00
|
|
|
m_corona->containments().at(0)->applets().at(0)->destroy();
|
2014-07-14 14:22:36 +02:00
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QSignalSpy spy(m_corona->containments().at(0)->applets().at(0), SIGNAL(destroyed()));
|
2014-07-14 14:22:36 +02:00
|
|
|
QVERIFY(spy.wait(1000));
|
2016-02-29 00:08:05 +01:00
|
|
|
QCOMPARE(m_corona->containments().at(0)->applets().count(), 2);
|
2014-07-14 14:22:36 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
//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);
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Containment *cont, m_corona->containments()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(cont->immutability(), Plasma::Types::UserImmutable);
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Applet *app, cont->applets()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(app->immutability(), Plasma::Types::UserImmutable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
m_corona->setImmutability(Plasma::Types::Mutable);
|
|
|
|
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Containment *cont, m_corona->containments()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(cont->immutability(), Plasma::Types::Mutable);
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Applet *app, cont->applets()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(app->immutability(), Plasma::Types::Mutable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
m_corona->setImmutability(Plasma::Types::SystemImmutable);
|
|
|
|
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
|
2014-07-14 19:17:47 +02:00
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Containment *cont, m_corona->containments()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Applet *app, cont->applets()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:01:56 +02:00
|
|
|
//can't unlock systemimmutable
|
|
|
|
m_corona->setImmutability(Plasma::Types::Mutable);
|
|
|
|
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
|
2014-07-14 19:17:47 +02:00
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Containment *cont, m_corona->containments()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(cont->immutability(), Plasma::Types::SystemImmutable);
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (Plasma::Applet *app, cont->applets()) {
|
2014-07-14 19:17:47 +02:00
|
|
|
QCOMPARE(app->immutability(), Plasma::Types::SystemImmutable);
|
|
|
|
}
|
|
|
|
}
|
2014-07-11 22:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(CoronaTest)
|
|
|
|
|