From 719590dea3e6d7f60f84915f1160541967c8501c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 11 Jul 2014 22:01:56 +0200 Subject: [PATCH] add a simple autotest for corona layouts --- autotests/CMakeLists.txt | 8 ++ autotests/coronatest.cpp | 117 ++++++++++++++++++++++++++++++ autotests/coronatest.h | 61 ++++++++++++++++ autotests/coronatestresources.qrc | 5 ++ autotests/plasma-test-appletsrc | 18 +++++ 5 files changed, 209 insertions(+) create mode 100644 autotests/coronatest.cpp create mode 100644 autotests/coronatest.h create mode 100644 autotests/coronatestresources.qrc create mode 100644 autotests/plasma-test-appletsrc diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 060132ded..18faab6d6 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -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) diff --git a/autotests/coronatest.cpp b/autotests/coronatest.cpp new file mode 100644 index 000000000..d66de71d4 --- /dev/null +++ b/autotests/coronatest.cpp @@ -0,0 +1,117 @@ +/******************************************************************************** +* Copyright 2010 by Martin Blumenstingl * +* * +* 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 +#include +#include + +/*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) + diff --git a/autotests/coronatest.h b/autotests/coronatest.h new file mode 100644 index 000000000..57b2aa6d6 --- /dev/null +++ b/autotests/coronatest.h @@ -0,0 +1,61 @@ +/****************************************************************************** +* Copyright 2014 Marco Martin * +* * +* 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 + +#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 + diff --git a/autotests/coronatestresources.qrc b/autotests/coronatestresources.qrc new file mode 100644 index 000000000..6a7b2b917 --- /dev/null +++ b/autotests/coronatestresources.qrc @@ -0,0 +1,5 @@ + + + plasma-test-appletsrc + + diff --git a/autotests/plasma-test-appletsrc b/autotests/plasma-test-appletsrc new file mode 100644 index 000000000..847b37c37 --- /dev/null +++ b/autotests/plasma-test-appletsrc @@ -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