From 10802b7bd029501c31384b80e96dbc2c1a173527 Mon Sep 17 00:00:00 2001 From: Bertjan Broeksema Date: Fri, 2 Nov 2007 22:17:29 +0000 Subject: [PATCH] Added tests for PackageMetaData. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732142 --- tests/CMakeLists.txt | 1 + tests/packagemetadatatest.cpp | 122 ++++++++++++++++++++++++++++++ tests/packagemetadatatest.desktop | 26 +++++++ tests/packagemetadatatest.h | 46 +++++++++++ 4 files changed, 195 insertions(+) create mode 100644 tests/packagemetadatatest.cpp create mode 100644 tests/packagemetadatatest.desktop create mode 100644 tests/packagemetadatatest.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ffce24a12..347a7a36f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,5 +9,6 @@ ENDMACRO(PLASMA_UNIT_TESTS) PLASMA_UNIT_TESTS( packagestructuretest + packagemetadatatest ) diff --git a/tests/packagemetadatatest.cpp b/tests/packagemetadatatest.cpp new file mode 100644 index 000000000..76fb6120b --- /dev/null +++ b/tests/packagemetadatatest.cpp @@ -0,0 +1,122 @@ +/****************************************************************************** +* Copyright 2007 by Bertjan Broeksema * +* * +* 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 "packagemetadatatest.h" + +#include +#include + +void PackageMetadataTest::init() +{ + pm = new Plasma::PackageMetadata; + + // Create data dir + mDataDir = QDir::homePath() + "/.kde-unit-test/share/config"; + QVERIFY(QDir().mkpath(mDataDir)); + + QDir dir(mDataDir); + QFile::copy(QString::fromLatin1(KDESRCDIR) + + QLatin1String("/packagemetadatatest.desktop"), mDataDir + + QLatin1String("/packagemetadatatest.desktop")); +} + +void PackageMetadataTest::cleanup() +{ + delete pm; + + // Clean things up. + removeDir(QLatin1String("share/config")); + QDir().rmpath(QDir::homePath() + "/.kde-unit-test/share"); +} + +// Copied from ktimezonetest.h +void PackageMetadataTest::removeDir(const QString &subdir) +{ + QDir local = QDir::homePath() + QLatin1String("/.kde-unit-test/") + subdir; + foreach(const QString &file, local.entryList(QDir::Files)) + if(!local.remove(file)) + qWarning("%s: removing failed", qPrintable( file )); + QCOMPARE((int)local.entryList(QDir::Files).count(), 0); + local.cdUp(); + QString subd = subdir; + subd.remove(QRegExp("^.*/")); + local.rmpath(subd); +} + +void PackageMetadataTest::read() +{ + pm->read("packagemetadatatest.desktop"); + + QVERIFY(pm->isComplete()); + + QCOMPARE(pm->name(), QString("test")); + QCOMPARE(pm->description(), QString("Some fancy test description")); + QCOMPARE(pm->serviceType(), QString("Plasma/Applet")); + QCOMPARE(pm->author(), QString("Bertjan Broeksema")); + QCOMPARE(pm->email(), QString("b.broeksema@kdemail.net")); + QCOMPARE(pm->version(), QString("pre0.1")); + QCOMPARE(pm->website(), QString("http://plasma.kde.org/")); + QCOMPARE(pm->license(), QString("GPL")); + QCOMPARE(pm->mainFile(), QString("Main file")); + QCOMPARE(pm->application(), QString("A Test name")); + QCOMPARE(pm->requiredVersion(), QString("1.2.3")); + //QCOMPARE(pm->releaseNotes(), QString("Package metadata test file")); + //QCOMPARE(pm->filenameToSave(), QString("Package metadata test file")); + QCOMPARE(pm->icon(), QString("test")); +} + +void PackageMetadataTest::write() +{ + pm->setName(QString("Package metadata test file")); + pm->setDescription(QString("Some fancy test description")); + pm->setServiceType(QString("Plasma/Applet")); + pm->setAuthor(QString("Bertjan Broeksema")); + pm->setEmail(QString("b.broeksema@kdemail.net")); + pm->setVersion(QString("pre0.1")); + pm->setWebsite(QString("http://plasma.kde.org/")); + pm->setLicense(QString("GPL")); + pm->setMainFile(QString("Main file")); + pm->setApplication(QString("A Test name")); + pm->setRequiredVersion(QString("1.2.3")); + //QCOMPARE(pm->releaseNotes(), QString("Package metadata test file")); + //QCOMPARE(pm->filenameToSave(), QString("Package metadata test file")); + pm->setIcon(QString("test")); + + pm->write("somefile.desktop"); + delete pm; + + pm = new Plasma::PackageMetadata("somefile.desktop"); + + QCOMPARE(pm->name(), QString("Package metadata test file")); + QCOMPARE(pm->description(), QString("Some fancy test description")); + QCOMPARE(pm->serviceType(), QString("Plasma/Applet")); + QCOMPARE(pm->author(), QString("Bertjan Broeksema")); + QCOMPARE(pm->email(), QString("b.broeksema@kdemail.net")); + QCOMPARE(pm->version(), QString("pre0.1")); + QCOMPARE(pm->website(), QString("http://plasma.kde.org/")); + QCOMPARE(pm->license(), QString("GPL")); + QCOMPARE(pm->mainFile(), QString("Main file")); + QCOMPARE(pm->application(), QString("A Test name")); + QCOMPARE(pm->requiredVersion(), QString("1.2.3")); + //QCOMPARE(pm->releaseNotes(), QString("Package metadata test file")); + //QCOMPARE(pm->filenameToSave(), QString("Package metadata test file")); + QCOMPARE(pm->icon(), QString("test")); +} + +QTEST_KDEMAIN(PackageMetadataTest, NoGUI) diff --git a/tests/packagemetadatatest.desktop b/tests/packagemetadatatest.desktop new file mode 100644 index 000000000..df45dbe72 --- /dev/null +++ b/tests/packagemetadatatest.desktop @@ -0,0 +1,26 @@ +[Desktop Entry] +Name=Package metadata test file +Comment=A test desktop file to test the PackageMetaData class. + +Icon=test +Type=Service +ServiceTypes=Plasma/Applet + +Description=Some fancy test description + +X-KDE-Library=some_test_library +X-KDE-PluginInfo-Author=Bertjan Broeksema +X-KDE-PluginInfo-Email=b.broeksema@kdemail.net +X-KDE-PluginInfo-Name=test +X-KDE-PluginInfo-Version=pre0.1 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=System test +X-KDE-PluginInfo-Depends=some_test_dep +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true + +X-KDE-Plasmagik-RequiredVersion=1.2.3 +X-KDE-Plasmagik-ApplicationName=A Test name +X-KDE-Plasmagik-MainFile=Main file + +X-PlasmoidCategory=System Information diff --git a/tests/packagemetadatatest.h b/tests/packagemetadatatest.h new file mode 100644 index 000000000..fcb0fc9e4 --- /dev/null +++ b/tests/packagemetadatatest.h @@ -0,0 +1,46 @@ +/****************************************************************************** +* Copyright 2007 by Bertjan Broeksema * +* * +* 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 PACKAGEMETADATATEST_H + +#include + +#include "plasma/packagemetadata.h" + +class PackageMetadataTest : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void init(); + void cleanup(); + +private Q_SLOTS: + void read(); + void write(); + +private: + void removeDir(const QString &subdir); + + Plasma::PackageMetadata *pm; + QString mDataDir; +}; + +#endif +