- Started woprking on package tests for a PlasmoidPackage.
- Fixed behavior of Package::isValid() Reviewed by aseigo. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732191
This commit is contained in:
parent
709136813b
commit
c9ff90ec0e
@ -76,14 +76,14 @@ bool Package::isValid() const
|
||||
}
|
||||
|
||||
foreach (const char *dir, d->structure.requiredDirectories()) {
|
||||
if (QFile::exists(d->basePath + '/' + d->structure.path(dir))) {
|
||||
if (!QFile::exists(d->basePath + d->structure.path(dir))) {
|
||||
d->valid = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const char *file, d->structure.requiredFiles()) {
|
||||
if (QFile::exists(d->basePath + '/' + d->structure.path(file))) {
|
||||
if (!QFile::exists(d->basePath + d->structure.path(file))) {
|
||||
d->valid = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ ENDMACRO(PLASMA_UNIT_TESTS)
|
||||
PLASMA_UNIT_TESTS(
|
||||
packagestructuretest
|
||||
packagemetadatatest
|
||||
plasmoidpackagetest
|
||||
)
|
||||
|
||||
|
101
tests/plasmoidpackagetest.cpp
Normal file
101
tests/plasmoidpackagetest.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2007 by Bertjan Broeksema <b.broeksema@kdemail.net> *
|
||||
* *
|
||||
* 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 "plasmoidpackagetest.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
#include "plasma/packages.cpp"
|
||||
|
||||
void PlasmoidPackageTest::init()
|
||||
{
|
||||
mPackage = QString("Package");
|
||||
mPackageRoot = QDir::homePath() + "/.kde-unit-test/packageRoot";
|
||||
|
||||
ps = new Plasma::PlasmoidStructure;
|
||||
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||
}
|
||||
|
||||
void PlasmoidPackageTest::cleanup()
|
||||
{
|
||||
delete ps;
|
||||
delete p;
|
||||
|
||||
// Clean things up.
|
||||
removeDir(QLatin1String("packageRoot/" + mPackage.toLatin1() + "/code"));
|
||||
removeDir(QLatin1String("packageRoot/" + mPackage.toLatin1()));
|
||||
QDir().rmpath(QDir::homePath() + "/.kde-unit-test/packageRoot");
|
||||
}
|
||||
|
||||
// Copied from ktimezonetest.h
|
||||
void PlasmoidPackageTest::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 PlasmoidPackageTest::isValid()
|
||||
{
|
||||
// A PlasmoidPackage is valid when:
|
||||
// - The package root exists.
|
||||
// - The package root consists an file named "code/main"
|
||||
QVERIFY(!p->isValid());
|
||||
|
||||
// Create the root and package dir.
|
||||
QVERIFY(QDir().mkpath(mPackageRoot));
|
||||
QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage));
|
||||
|
||||
// Should still be invalid.
|
||||
delete p;
|
||||
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||
qDebug() << p->isValid();
|
||||
QVERIFY(!p->isValid());
|
||||
|
||||
// Create the code dir.
|
||||
QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage + "/code"));
|
||||
|
||||
// No main file yet so should still be invalid.
|
||||
delete p;
|
||||
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||
QVERIFY(!p->isValid());
|
||||
|
||||
// Create the main file.
|
||||
QFile file(mPackageRoot + "/" + mPackage + "/code/main");
|
||||
QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
|
||||
|
||||
QTextStream out(&file);
|
||||
out << "THIS IS A PLASMOID SCRIPT.....";
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
// Main file exists so should be valid now.
|
||||
delete p;
|
||||
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||
QVERIFY(p->isValid());
|
||||
}
|
||||
|
||||
QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI)
|
47
tests/plasmoidpackagetest.h
Normal file
47
tests/plasmoidpackagetest.h
Normal file
@ -0,0 +1,47 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2007 by Bertjan Broeksema <b.broeksema@kdemail.net> *
|
||||
* *
|
||||
* 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 PACKAGETEST_H
|
||||
|
||||
#include <qtest_kde.h>
|
||||
|
||||
#include "plasma/package.h"
|
||||
|
||||
class PlasmoidPackageTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
private Q_SLOTS:
|
||||
void isValid();
|
||||
|
||||
private:
|
||||
void removeDir(const QString &subdir);
|
||||
|
||||
QString mPackageRoot;
|
||||
QString mPackage;
|
||||
Plasma::PackageStructure *ps;
|
||||
Plasma::Package *p;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user