plasma-framework/autotests/packagestructuretest.cpp

183 lines
5.4 KiB
C++
Raw Normal View History

/******************************************************************************
* 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"
#include <kconfig.h>
#include <kconfiggroup.h>
2013-07-29 19:05:59 +02:00
#include <QDebug>
#include <klocalizedstring.h>
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"
2011-07-15 12:58:56 +02:00
class NoPrefixes : public Plasma::Package
{
public:
explicit NoPrefixes()
2013-02-08 14:40:30 +01:00
: Plasma::Package(new Plasma::PackageStructure)
{
setContentsPrefixPaths(QStringList());
addDirectoryDefinition("bin", "bin", "bin");
addFileDefinition("MultiplePaths", "first", "Description proper");
addFileDefinition("MultiplePaths", "second", "Description proper");
setPath("/");
}
};
2013-02-15 15:16:54 +01:00
void PackageStructureTest::initTestCase()
{
m_packagePath = QFINDTESTDATA("data/testpackage");
2013-02-15 15:16:54 +01:00
ps = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
ps.setPath(m_packagePath);
}
void PackageStructureTest::copyPerformance()
{
// seed the cache first
ps.filePath("mainscript");
QTime t;
t.start();
for (int i = 0; i < 100000; ++i) {
Plasma::Package foo(ps);
const QString bar = foo.filePath("mainscript");
}
QVERIFY(t.elapsed() < 400);
}
void PackageStructureTest::emptyContentsPrefix()
{
2011-07-15 12:58:56 +02:00
NoPrefixes package;
QString path(package.filePath("bin", "ls"));
//qDebug() << path;
QCOMPARE(path, QString("/bin/ls"));
}
void PackageStructureTest::multiplePaths()
{
NoPrefixes package;
QCOMPARE(package.name("MultiplePaths"), QString("Description proper"));
}
void PackageStructureTest::directories()
{
2014-04-26 01:45:47 +02:00
QList<const char *> dirs;
dirs << "config" << "data" << "images" << "theme" << "scripts" << "translations" << "ui";
2014-04-26 01:45:47 +02:00
QList<const char *> psDirs = ps.directories();
QCOMPARE(dirs.count(), psDirs.count());
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);
}
}
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);
}
void PackageStructureTest::files()
{
2014-04-26 01:45:47 +02:00
QList<const char *> files;
files << "mainconfigui" << "mainconfigxml" << "mainscript";
2014-04-26 01:45:47 +02:00
QList<const char *> psFiles = ps.files();
//for (int i = 0; i < psFiles.count(); ++i) {
// qDebug() << psFiles[i];
//}
foreach (const char *file, psFiles) {
bool found = false;
foreach (const char *check, files) {
if (qstrcmp(file, check)) {
found = true;
break;
}
}
QVERIFY(found);
}
}
void PackageStructureTest::requiredFiles()
{
2014-04-26 01:45:47 +02:00
QList<const char *> files;
files << "mainscript";
2014-04-26 01:45:47 +02: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]);
}
}
void PackageStructureTest::path()
{
2013-02-15 15:16:54 +01:00
QCOMPARE(ps.filePath("images"), QDir(m_packagePath + QString("/contents/images")).canonicalPath());
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());
}
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"));
}
void PackageStructureTest::required()
{
2011-07-15 12:58:56 +02:00
QVERIFY(ps.isRequired("mainscript"));
}
2011-05-06 12:26:39 +02:00
void PackageStructureTest::mimeTypes()
{
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);
QCOMPARE(ps.mimeTypes("theme"), mimeTypes);
}
QTEST_MAIN(PackageStructureTest)