add a simple autotest for corona layouts

This commit is contained in:
Marco Martin 2014-07-11 22:01:56 +02:00
parent 054a38b9d0
commit 719590dea3
5 changed files with 209 additions and 0 deletions

View File

@ -4,8 +4,10 @@ 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(Qt5Widgets REQUIRED)
# add_definitions( -DKDESRCDIR=${CMAKE_CURRENT_SOURCE_DIR} )
@ -36,6 +38,12 @@ 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 )
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)
add_test(plasma-storagetest storagetest)
ecm_mark_as_test(storagetest)

117
autotests/coronatest.cpp Normal file
View File

@ -0,0 +1,117 @@
/********************************************************************************
* Copyright 2010 by Martin Blumenstingl <darklight.xdarklight@googlemail.com> *
* *
* 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 <QStandardPaths>
#include <QApplication>
/*virtual Plasma::Applet *SimpleLoader::internalLoadApplet(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList())
{
returh new Plasma::Applet();
}*/
QRect SimpleCorona::screenGeometry(int screen) const
{
//completely arbitrary, still not tested
return QRect(100*screen, 100, 100, 100);
}
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);
//qDebug() << "waiting for signal";
//QSignalSpy spy(KSycoca::self(), SIGNAL(databaseChanged(QStringList)));
//QVERIFY(spy.wait(10000));
//qDebug() << "got signal";
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();
}
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()
{
//startup completion signals
QEXPECT_FAIL("", "TODO: complete startup", Continue);
QVERIFY(m_corona->isStartupCompleted());
QEXPECT_FAIL("", "TODO: complete uiReady signals", Continue);
QVERIFY(m_corona->containments().first()->isUiReady());
//TODO: applet creation and deletion
}
//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);
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::Mutable);
m_corona->setImmutability(Plasma::Types::SystemImmutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
//can't unlock systemimmutable
m_corona->setImmutability(Plasma::Types::Mutable);
QCOMPARE(m_corona->immutability(), Plasma::Types::SystemImmutable);
}
QTEST_MAIN(CoronaTest)

61
autotests/coronatest.h Normal file
View File

@ -0,0 +1,61 @@
/******************************************************************************
* 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 "plasma/corona.h"
/*class SimpleLoader : public Plasma::PluginLoader
{
Q_OBJECT
protected:
virtual Applet *internalLoadApplet(const QString &name, uint appletId = 0,
const QVariantList &args = QVariantList());
};*/
class SimpleCorona : public Plasma::Corona
{
Q_OBJECT
public:
QRect screenGeometry(int) const;
};
class CoronaTest : public QObject
{
Q_OBJECT
public Q_SLOTS:
void initTestCase();
void cleanupTestCase();
private Q_SLOTS:
void restore();
void startupCompletion();
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=invalid
[Containments][1][Applets][2]
immutability=1
plugin=invalid
[Containments][1][Applets][3]
immutability=1
plugin=invalid
[General]
immutability=1