2008-11-04 00:08:39 +01: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"
|
|
|
|
|
2008-11-04 10:36:00 +01:00
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kconfiggroup.h>
|
2013-07-29 19:05:59 +02:00
|
|
|
#include <QDebug>
|
2012-09-17 18:56:56 +02:00
|
|
|
#include <klocalizedstring.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-07-21 14:48:12 +02:00
|
|
|
#include "applet.h"
|
2013-02-08 14:40:30 +01:00
|
|
|
#include "packagestructure.h"
|
2011-07-21 14:48:12 +02:00
|
|
|
#include "pluginloader.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-07-15 12:58:56 +02:00
|
|
|
class NoPrefixes : public Plasma::Package
|
2010-12-15 08:14:43 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit NoPrefixes()
|
2013-02-08 14:40:30 +01:00
|
|
|
: Plasma::Package(new Plasma::PackageStructure)
|
2010-12-15 08:14:43 +01:00
|
|
|
{
|
|
|
|
setContentsPrefixPaths(QStringList());
|
|
|
|
addDirectoryDefinition("bin", "bin", "bin");
|
2012-11-01 17:39:16 +01:00
|
|
|
addFileDefinition("MultiplePaths", "first", "Description proper");
|
|
|
|
addFileDefinition("MultiplePaths", "second", "Description proper");
|
2011-07-19 21:37:08 +02:00
|
|
|
setPath("/");
|
2010-12-15 08:14:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-15 15:16:54 +01:00
|
|
|
void PackageStructureTest::initTestCase()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-06-19 02:06:55 +02:00
|
|
|
m_packagePath = QFINDTESTDATA("data/testpackage");
|
2013-02-15 15:16:54 +01:00
|
|
|
ps = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
2011-07-19 21:37:08 +02:00
|
|
|
ps.setPath(m_packagePath);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2014-08-08 14:12:09 +02:00
|
|
|
void PackageStructureTest::validStructures()
|
|
|
|
{
|
|
|
|
QVERIFY(ps.hasValidStructure());
|
|
|
|
QVERIFY(!Plasma::Package().hasValidStructure());
|
|
|
|
QVERIFY(!Plasma::PluginLoader::self()->loadPackage("doesNotExist").hasValidStructure());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::validPackages()
|
|
|
|
{
|
|
|
|
QVERIFY(ps.isValid());
|
|
|
|
QVERIFY(!Plasma::Package().isValid());
|
|
|
|
QVERIFY(!Plasma::PluginLoader::self()->loadPackage("doesNotExist").isValid());
|
|
|
|
QVERIFY(NoPrefixes().isValid());
|
|
|
|
|
|
|
|
Plasma::Package p = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
|
|
|
QVERIFY(!p.isValid());
|
|
|
|
p.setPath("/does/not/exist");
|
|
|
|
QVERIFY(!p.isValid());
|
|
|
|
p.setPath(ps.path());
|
|
|
|
QVERIFY(p.isValid());
|
|
|
|
}
|
|
|
|
|
2011-07-22 17:24:10 +02:00
|
|
|
void PackageStructureTest::copyPerformance()
|
|
|
|
{
|
|
|
|
// seed the cache first
|
|
|
|
ps.filePath("mainscript");
|
|
|
|
|
2015-08-01 13:45:29 +02:00
|
|
|
QBENCHMARK {
|
2011-07-22 17:24:10 +02:00
|
|
|
Plasma::Package foo(ps);
|
|
|
|
const QString bar = foo.filePath("mainscript");
|
2015-08-01 13:45:29 +02:00
|
|
|
Q_UNUSED(bar);
|
2011-07-22 17:24:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 06:45:38 +02:00
|
|
|
void PackageStructureTest::mutateAfterCopy()
|
|
|
|
{
|
|
|
|
const bool mainscriptRequired = ps.isRequired("mainscript");
|
|
|
|
const QStringList imageMimeTypes = ps.mimeTypes("images");
|
2014-08-08 07:19:27 +02:00
|
|
|
const QStringList defaultMimeTypes = ps.mimeTypes("translations");
|
|
|
|
const QString packageRoot = ps.defaultPackageRoot();
|
|
|
|
const bool externalPaths = ps.allowExternalPaths();
|
|
|
|
const QString servicePrefix = ps.servicePrefix();
|
|
|
|
const QStringList contentsPrefixPaths = ps.contentsPrefixPaths();
|
2014-08-08 07:22:31 +02:00
|
|
|
const QList<const char *> files = ps.files();
|
|
|
|
const QList<const char *> dirs = ps.directories();
|
2014-08-08 06:45:38 +02:00
|
|
|
|
|
|
|
Plasma::Package copy(ps);
|
|
|
|
|
|
|
|
copy.setRequired("mainscript", !mainscriptRequired);
|
2014-08-08 07:19:27 +02:00
|
|
|
QCOMPARE(ps.isRequired("mainscript"), mainscriptRequired);
|
|
|
|
QCOMPARE(copy.isRequired("mainscript"), !mainscriptRequired);
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
const QString copyPackageRoot = packageRoot + "more/";
|
|
|
|
copy.setDefaultPackageRoot(copyPackageRoot);
|
|
|
|
QCOMPARE(ps.defaultPackageRoot(), packageRoot);
|
|
|
|
QCOMPARE(copy.defaultPackageRoot(), copyPackageRoot);
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
copy.setAllowExternalPaths(!externalPaths);
|
|
|
|
QCOMPARE(ps.allowExternalPaths(), externalPaths);
|
|
|
|
QCOMPARE(copy.allowExternalPaths(), !externalPaths);
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
const QString copyServicePrefix = packageRoot + "more/";
|
|
|
|
copy.setServicePrefix(copyServicePrefix);
|
|
|
|
QCOMPARE(ps.servicePrefix(), servicePrefix);
|
|
|
|
QCOMPARE(copy.servicePrefix(), copyServicePrefix);
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
QStringList copyContentsPrefixPaths = contentsPrefixPaths;
|
|
|
|
copyContentsPrefixPaths << "more/";
|
|
|
|
copy.setContentsPrefixPaths(copyContentsPrefixPaths);
|
|
|
|
QCOMPARE(ps.contentsPrefixPaths(), contentsPrefixPaths);
|
|
|
|
QCOMPARE(copy.contentsPrefixPaths(), copyContentsPrefixPaths);
|
2014-08-08 06:45:38 +02:00
|
|
|
|
2014-08-08 07:22:31 +02:00
|
|
|
copy = ps;
|
|
|
|
copy.addFileDefinition("nonsense", "foobar", QString());
|
|
|
|
QCOMPARE(ps.files(), files);
|
|
|
|
QVERIFY(ps.files() != copy.files());
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
copy.addDirectoryDefinition("nonsense", "foobar", QString());
|
|
|
|
QCOMPARE(ps.directories(), dirs);
|
|
|
|
QVERIFY(ps.directories() != copy.directories());
|
|
|
|
|
2014-08-08 07:24:00 +02:00
|
|
|
copy = ps;
|
|
|
|
copy.removeDefinition("mainscript");
|
|
|
|
QCOMPARE(ps.files(), files);
|
|
|
|
QVERIFY(ps.files() != copy.files());
|
|
|
|
|
2014-08-08 06:45:38 +02:00
|
|
|
#ifndef PLASMA_NO_PACKAGE_EXTRADATA
|
2014-08-08 07:19:27 +02:00
|
|
|
copy = ps;
|
2014-08-08 06:45:38 +02:00
|
|
|
QVERIFY(!imageMimeTypes.isEmpty());
|
|
|
|
QStringList copyMimeTypes;
|
|
|
|
copyMimeTypes << imageMimeTypes.first();
|
|
|
|
copy.setMimeTypes("images", copyMimeTypes);
|
|
|
|
QCOMPARE(ps.mimeTypes("images"), imageMimeTypes);
|
|
|
|
QCOMPARE(copy.mimeTypes("images"), copyMimeTypes);
|
2014-08-08 07:19:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
copy = ps;
|
|
|
|
QStringList copyDefaultMimeTypes = defaultMimeTypes;
|
|
|
|
copyDefaultMimeTypes << "rubbish";
|
|
|
|
copy.setDefaultMimeTypes(copyDefaultMimeTypes);
|
|
|
|
QCOMPARE(ps.mimeTypes("translations"), defaultMimeTypes);
|
|
|
|
QCOMPARE(copy.mimeTypes("translations"), copyDefaultMimeTypes);
|
2014-08-08 06:45:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-12-15 08:14:43 +01:00
|
|
|
void PackageStructureTest::emptyContentsPrefix()
|
|
|
|
{
|
2011-07-15 12:58:56 +02:00
|
|
|
NoPrefixes package;
|
2010-12-15 08:14:43 +01:00
|
|
|
QString path(package.filePath("bin", "ls"));
|
2011-07-19 21:37:08 +02:00
|
|
|
//qDebug() << path;
|
2010-12-15 08:14:43 +01:00
|
|
|
QCOMPARE(path, QString("/bin/ls"));
|
|
|
|
}
|
|
|
|
|
2012-11-01 17:39:16 +01:00
|
|
|
void PackageStructureTest::multiplePaths()
|
|
|
|
{
|
|
|
|
NoPrefixes package;
|
|
|
|
QCOMPARE(package.name("MultiplePaths"), QString("Description proper"));
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void PackageStructureTest::directories()
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> dirs;
|
2013-05-11 13:25:35 +02:00
|
|
|
dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui";
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> psDirs = ps.directories();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QCOMPARE(dirs.count(), psDirs.count());
|
2010-10-13 18:02:19 +02:00
|
|
|
|
2011-07-22 17:24:10 +02:00
|
|
|
foreach (const char *dir, psDirs) {
|
|
|
|
bool found = false;
|
|
|
|
foreach (const char *check, dirs) {
|
|
|
|
if (qstrcmp(dir, check)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(found);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const char *dir, dirs) {
|
|
|
|
bool found = false;
|
|
|
|
foreach (const char *check, psDirs) {
|
|
|
|
if (qstrcmp(dir, check)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(found);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::requiredDirectories()
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> dirs;
|
2011-07-15 12:58:56 +02:00
|
|
|
QCOMPARE(ps.requiredDirectories(), dirs);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::files()
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> files;
|
2012-10-05 18:08:33 +02:00
|
|
|
files << "mainconfigui" << "mainconfigxml" << "mainscript";
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> psFiles = ps.files();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-15 15:08:07 +02:00
|
|
|
//for (int i = 0; i < psFiles.count(); ++i) {
|
|
|
|
// qDebug() << psFiles[i];
|
|
|
|
//}
|
2011-07-22 17:24:10 +02:00
|
|
|
foreach (const char *file, psFiles) {
|
|
|
|
bool found = false;
|
|
|
|
foreach (const char *check, files) {
|
|
|
|
if (qstrcmp(file, check)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY(found);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::requiredFiles()
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> files;
|
2008-11-04 00:08:39 +01:00
|
|
|
files << "mainscript";
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> psFiles = ps.requiredFiles();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QCOMPARE(files.count(), psFiles.count());
|
|
|
|
for (int i = 0; i < files.count(); ++i) {
|
|
|
|
QCOMPARE(files[i], psFiles[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::path()
|
|
|
|
{
|
2013-02-15 15:16:54 +01:00
|
|
|
QCOMPARE(ps.filePath("images"), QDir(m_packagePath + QString("/contents/images")).canonicalPath());
|
2013-05-11 13:25:35 +02:00
|
|
|
QCOMPARE(ps.filePath("theme"), QDir(m_packagePath + QString("/contents/theme")).canonicalPath());
|
2013-02-15 15:16:54 +01:00
|
|
|
QCOMPARE(ps.filePath("mainscript"), QFileInfo(m_packagePath + QString("/contents/ui/main.qml")).canonicalFilePath());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::name()
|
|
|
|
{
|
2011-07-15 12:58:56 +02:00
|
|
|
QCOMPARE(ps.name("config"), i18n("Configuration Definitions"));
|
|
|
|
QCOMPARE(ps.name("mainscript"), i18n("Main Script File"));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructureTest::required()
|
|
|
|
{
|
2011-07-15 12:58:56 +02:00
|
|
|
QVERIFY(ps.isRequired("mainscript"));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-05-06 12:26:39 +02:00
|
|
|
void PackageStructureTest::mimeTypes()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-05-06 12:26:39 +02:00
|
|
|
QStringList mimeTypes;
|
|
|
|
mimeTypes << "image/svg+xml" << "image/png" << "image/jpeg";
|
2011-07-15 12:58:56 +02:00
|
|
|
QCOMPARE(ps.mimeTypes("images"), mimeTypes);
|
2013-05-11 13:25:35 +02:00
|
|
|
QCOMPARE(ps.mimeTypes("theme"), mimeTypes);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-12-18 12:18:08 +01:00
|
|
|
QTEST_MAIN(PackageStructureTest)
|
2008-11-04 00:08:39 +01:00
|
|
|
|