2007-10-22 03:30:29 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@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. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include "packagestructuretest.h"
|
2007-11-26 10:28:48 +01:00
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
#include <KConfig>
|
|
|
|
#include <KConfigGroup>
|
2007-11-26 10:28:48 +01:00
|
|
|
#include <KDebug>
|
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
#include "plasma/packagestructure.h"
|
2008-02-26 21:48:02 +01:00
|
|
|
#include "plasma/applet.h"
|
2007-10-22 03:30:29 +02:00
|
|
|
|
|
|
|
void PackageStructureTest::init()
|
|
|
|
{
|
2008-02-26 21:48:02 +01:00
|
|
|
ps = Plasma::Applet::packageStructure();
|
2007-10-22 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::type()
|
|
|
|
{
|
|
|
|
QCOMPARE(ps->type(), QString("Plasmoid"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::directories()
|
|
|
|
{
|
|
|
|
QList<const char*> dirs;
|
2008-02-26 21:48:02 +01:00
|
|
|
dirs << "config" << "images" << "scripts" << "ui";
|
2007-10-22 03:30:29 +02:00
|
|
|
|
|
|
|
QList<const char*> psDirs = ps->directories();
|
|
|
|
|
2007-11-26 10:28:48 +01:00
|
|
|
QCOMPARE(dirs.count(), psDirs.count());
|
2008-02-26 21:48:02 +01:00
|
|
|
for (int i = 0; i < psDirs.count(); ++i) {
|
|
|
|
QVERIFY(qstrcmp(dirs[i], psDirs[i]) == 0);
|
2007-11-26 10:28:48 +01:00
|
|
|
}
|
2007-10-22 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::requiredDirectories()
|
|
|
|
{
|
|
|
|
QList<const char*> dirs;
|
|
|
|
QCOMPARE(ps->requiredDirectories(), dirs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::files()
|
|
|
|
{
|
|
|
|
QList<const char*> files;
|
2008-10-04 13:00:13 +02:00
|
|
|
files << "mainconfigui" << "mainconfigxml" << "mainscript";
|
2007-10-22 03:30:29 +02:00
|
|
|
|
|
|
|
QList<const char*> psFiles = ps->files();
|
|
|
|
|
2007-11-26 10:28:48 +01:00
|
|
|
QCOMPARE(files.count(), psFiles.count());
|
|
|
|
for (int i = 0; i < files.count(); ++i) {
|
|
|
|
QCOMPARE(files[i], psFiles[i]);
|
|
|
|
}
|
2007-10-22 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::requiredFiles()
|
|
|
|
{
|
|
|
|
QList<const char*> files;
|
|
|
|
files << "mainscript";
|
2007-11-26 10:28:48 +01:00
|
|
|
|
|
|
|
QList<const char*> psFiles = ps->requiredFiles();
|
|
|
|
|
|
|
|
QCOMPARE(files.count(), psFiles.count());
|
|
|
|
for (int i = 0; i < files.count(); ++i) {
|
|
|
|
QCOMPARE(files[i], psFiles[i]);
|
|
|
|
}
|
2007-10-22 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::path()
|
|
|
|
{
|
|
|
|
QCOMPARE(ps->path("images"), QString("images"));
|
|
|
|
QCOMPARE(ps->path("mainscript"), QString("code/main"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::name()
|
|
|
|
{
|
|
|
|
QCOMPARE(ps->name("config"), i18n("Configuration Definitions"));
|
|
|
|
QCOMPARE(ps->name("mainscript"), i18n("Main Script File"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::required()
|
|
|
|
{
|
2008-05-27 21:36:25 +02:00
|
|
|
QVERIFY(ps->isRequired("mainscript"));
|
2007-10-22 03:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::mimetypes()
|
|
|
|
{
|
|
|
|
QStringList mimetypes;
|
|
|
|
mimetypes << "image/svg+xml" << "image/png" << "image/jpeg";
|
|
|
|
QCOMPARE(ps->mimetypes("images"), mimetypes);
|
|
|
|
}
|
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
void PackageStructureTest::read()
|
|
|
|
{
|
|
|
|
QString structurePath = QString(KDESRCDIR) + "/plasmoidpackagerc";
|
2008-05-27 21:36:25 +02:00
|
|
|
KConfig config(structurePath, KConfig::SimpleConfig);
|
2008-02-26 21:48:02 +01:00
|
|
|
Plasma::PackageStructure structure;
|
|
|
|
structure.read(&config);
|
2007-12-02 14:16:39 +01:00
|
|
|
|
|
|
|
// check some names
|
|
|
|
QCOMPARE(structure.name("config"), i18n("Configuration Definitions"));
|
|
|
|
QCOMPARE(structure.name("mainscript"), i18n("Main Script File"));
|
|
|
|
|
|
|
|
// check some paths
|
|
|
|
QCOMPARE(structure.path("images"), QString("images"));
|
|
|
|
QCOMPARE(structure.path("mainscript"), QString("code/main"));
|
|
|
|
|
|
|
|
// compare files
|
|
|
|
QList<const char *> files;
|
|
|
|
files << "mainconfiggui" << "mainconfigxml" << "mainscript";
|
|
|
|
|
|
|
|
QList<const char *> psFiles = structure.files();
|
|
|
|
|
|
|
|
QCOMPARE(psFiles.count(), files.count());
|
|
|
|
for (int i = 0; i < files.count(); ++i) {
|
|
|
|
QCOMPARE(psFiles[i], files[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare required files
|
|
|
|
QList<const char *> reqFiles = structure.requiredFiles();
|
|
|
|
QCOMPARE(reqFiles.count(), 1);
|
|
|
|
QCOMPARE(reqFiles[0], "mainscript");
|
|
|
|
|
|
|
|
// compare directories
|
|
|
|
QList <const char *> dirs;
|
2008-06-18 01:21:39 +02:00
|
|
|
dirs << "config" << "configui" << "images" << "scripts";
|
2007-12-02 14:16:39 +01:00
|
|
|
QList <const char *> psDirs = structure.directories();
|
|
|
|
QCOMPARE(psDirs.count(), dirs.count());
|
|
|
|
for (int i = 0; i < dirs.count(); i++) {
|
|
|
|
QCOMPARE(psDirs[i], dirs[i]);
|
|
|
|
}
|
|
|
|
QCOMPARE(structure.requiredDirectories().size(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::write()
|
|
|
|
{
|
|
|
|
QString file1 = QDir::homePath() + "/.kde-unit-test/packagerc";
|
|
|
|
QString file2 = QString(KDESRCDIR) + "/plasmoidpackagerc";
|
|
|
|
|
2008-05-27 21:36:25 +02:00
|
|
|
KConfig config(file1, KConfig::SimpleConfig);
|
2007-12-02 14:16:39 +01:00
|
|
|
ps->write(&config);
|
|
|
|
|
|
|
|
// check type
|
|
|
|
QCOMPARE(config.group("").readEntry("Type", QString()), QString("Plasmoid"));
|
|
|
|
|
|
|
|
// check groups
|
|
|
|
QStringList groups;
|
2008-02-26 21:48:02 +01:00
|
|
|
groups << "images" << "config" << "scripts"
|
2008-10-04 13:00:13 +02:00
|
|
|
<< "mainconfigui" << "mainconfigxml" << "mainscript" << "ui";
|
2007-12-02 14:16:39 +01:00
|
|
|
groups.sort();
|
2008-02-26 21:48:02 +01:00
|
|
|
|
|
|
|
QStringList actualGroups = config.groupList();
|
|
|
|
actualGroups.sort();
|
|
|
|
QCOMPARE(actualGroups, groups);
|
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
// check scripts
|
|
|
|
KConfigGroup scripts = config.group("scripts");
|
|
|
|
QCOMPARE(scripts.readEntry("Path", QString()), QString("code"));
|
|
|
|
QCOMPARE(scripts.readEntry("Name", QString()), QString("Executable Scripts"));
|
|
|
|
QCOMPARE(scripts.readEntry("Mimetypes", QStringList()), QStringList() << "text/*");
|
|
|
|
QCOMPARE(scripts.readEntry("Directory", false), true);
|
|
|
|
QCOMPARE(scripts.readEntry("Required", false), false);
|
|
|
|
}
|
|
|
|
|
2007-10-22 03:30:29 +02:00
|
|
|
QTEST_KDEMAIN(PackageStructureTest, NoGUI)
|
|
|
|
|
|
|
|
//#include "packagestructuretest.moc"
|
|
|
|
|