diff --git a/tests/packagestructuretest.cpp b/tests/packagestructuretest.cpp index f955770e3..6ecb06b51 100644 --- a/tests/packagestructuretest.cpp +++ b/tests/packagestructuretest.cpp @@ -23,15 +23,13 @@ #include #include -#include "plasma/package.h" -#include "plasma/packagestructure.h" #include "plasma/applet.h" -class NoPrefixes : public Plasma::PackageStructure +class NoPrefixes : public Plasma::Package { public: explicit NoPrefixes() - : Plasma::PackageStructure(0, "StructureLess") + : Plasma::Package() { setContentsPrefixPaths(QStringList()); addDirectoryDefinition("bin", "bin", "bin"); @@ -41,29 +39,24 @@ public: void PackageStructureTest::init() { - ps = Plasma::Applet::packageStructure(); + ps = Plasma::Package::load("Plasma/Applet"); } void PackageStructureTest::emptyContentsPrefix() { - Plasma::PackageStructure::Ptr structure(new NoPrefixes); - Plasma::Package package("/", structure); + NoPrefixes package; + package.setPath("/"); QString path(package.filePath("bin", "ls")); qDebug() << path; QCOMPARE(path, QString("/bin/ls")); } -void PackageStructureTest::type() -{ - QCOMPARE(ps->type(), QString("Plasmoid")); -} - void PackageStructureTest::directories() { QList dirs; dirs << "animations" << "config" << "data" << "images" << "scripts" << "translations" << "ui"; - QList psDirs = ps->directories(); + QList psDirs = ps.directories(); QCOMPARE(dirs.count(), psDirs.count()); @@ -75,7 +68,7 @@ void PackageStructureTest::directories() void PackageStructureTest::requiredDirectories() { QList dirs; - QCOMPARE(ps->requiredDirectories(), dirs); + QCOMPARE(ps.requiredDirectories(), dirs); } void PackageStructureTest::files() @@ -83,7 +76,7 @@ void PackageStructureTest::files() QList files; files << "defaultconfig" << "mainconfigui" << "mainconfigxml" << "mainscript"; - QList psFiles = ps->files(); + QList psFiles = ps.files(); //for (int i = 0; i < psFiles.count(); ++i) { // qDebug() << psFiles[i]; @@ -99,7 +92,7 @@ void PackageStructureTest::requiredFiles() QList files; files << "mainscript"; - QList psFiles = ps->requiredFiles(); + QList psFiles = ps.requiredFiles(); QCOMPARE(files.count(), psFiles.count()); for (int i = 0; i < files.count(); ++i) { @@ -109,33 +102,33 @@ void PackageStructureTest::requiredFiles() void PackageStructureTest::path() { - QCOMPARE(ps->path("images"), QString("images")); - QCOMPARE(ps->path("mainscript"), QString("code/main")); + QCOMPARE(ps.filePath("images"), QString("images")); + QCOMPARE(ps.filePath("mainscript"), QString("code/main")); } void PackageStructureTest::name() { - QCOMPARE(ps->name("config"), i18n("Configuration Definitions")); - QCOMPARE(ps->name("mainscript"), i18n("Main Script File")); + QCOMPARE(ps.name("config"), i18n("Configuration Definitions")); + QCOMPARE(ps.name("mainscript"), i18n("Main Script File")); } void PackageStructureTest::required() { - QVERIFY(ps->isRequired("mainscript")); + QVERIFY(ps.isRequired("mainscript")); } void PackageStructureTest::mimeTypes() { QStringList mimeTypes; mimeTypes << "image/svg+xml" << "image/png" << "image/jpeg"; - QCOMPARE(ps->mimeTypes("images"), mimeTypes); + QCOMPARE(ps.mimeTypes("images"), mimeTypes); } void PackageStructureTest::read() { QString structurePath = QString(KDESRCDIR) + "/plasmoidpackagerc"; KConfig config(structurePath, KConfig::SimpleConfig); - Plasma::PackageStructure structure; + Plasma::Package structure; structure.read(&config); // check some names @@ -143,8 +136,8 @@ void PackageStructureTest::read() QCOMPARE(structure.name("mainscript"), i18n("Main Script File")); // check some paths - QCOMPARE(structure.path("images"), QString("images")); - QCOMPARE(structure.path("mainscript"), QString("code/main")); + QCOMPARE(structure.filePath("images"), QString("images")); + QCOMPARE(structure.filePath("mainscript"), QString("code/main")); // compare files QList files; @@ -179,7 +172,7 @@ void PackageStructureTest::write() QString file2 = QString(KDESRCDIR) + "/plasmoidpackagerc"; KConfig config(file1, KConfig::SimpleConfig); - ps->write(&config); + ps.write(&config); // check type QCOMPARE(config.group("").readEntry("Type", QString()), QString("Plasmoid")); diff --git a/tests/packagestructuretest.h b/tests/packagestructuretest.h index 76a39c30e..42027e0c8 100644 --- a/tests/packagestructuretest.h +++ b/tests/packagestructuretest.h @@ -21,7 +21,7 @@ #include -#include "plasma/packagestructure.h" +#include "plasma/package.h" class PackageStructureTest : public QObject { @@ -32,7 +32,6 @@ public Q_SLOTS: private Q_SLOTS: void emptyContentsPrefix(); - void type(); void directories(); void requiredDirectories(); void files(); @@ -47,7 +46,7 @@ private Q_SLOTS: //TODO: add tests for copy construction private: - Plasma::PackageStructure::Ptr ps; + Plasma::Package ps; }; #endif diff --git a/tests/plasmoidpackagetest.cpp b/tests/plasmoidpackagetest.cpp index ecf7b430b..c777778bf 100644 --- a/tests/plasmoidpackagetest.cpp +++ b/tests/plasmoidpackagetest.cpp @@ -26,20 +26,16 @@ #include #include "plasma/applet.h" -#include "plasma/packagemetadata.h" void PlasmoidPackageTest::init() { - mPackage = QString("Package"); - mPackageRoot = QDir::homePath() + "/.kde-unit-test/packageRoot"; - ps = Plasma::Applet::packageStructure(); + m_package = QString("Package"); + m_packageRoot = QDir::homePath() + "/.kde-unit-test/packageRoot"; + m_defaultPackage = Plasma::Package::load("Plasma/Applet"); } void PlasmoidPackageTest::cleanup() { - delete p; - p = 0; - // Clean things up. QDir local(QDir::homePath() + QLatin1String("/.kde-unit-test/packageRoot")); foreach (const QString &dir, local.entryList(QDir::Dirs)) { @@ -68,17 +64,17 @@ void PlasmoidPackageTest::removeDir(const QString &subdir) void PlasmoidPackageTest::createTestPackage(const QString &packageName) { - QDir pRoot(mPackageRoot); + QDir pRoot(m_packageRoot); // Create the root and package dir. if (!pRoot.exists()) { - QVERIFY(QDir().mkpath(mPackageRoot)); + QVERIFY(QDir().mkpath(m_packageRoot)); } // Create the package dir - QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName)); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName)); // Create the metadata.desktop file - QFile file(mPackageRoot + "/" + packageName + "/metadata.desktop"); + QFile file(m_packageRoot + "/" + packageName + "/metadata.desktop"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); @@ -90,10 +86,10 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName) file.close(); // Create the code dir. - QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName + "/contents/code")); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName + "/contents/code")); // Create the main file. - file.setFileName(mPackageRoot + "/" + packageName + "/contents/code/main"); + file.setFileName(m_packageRoot + "/" + packageName + "/contents/code/main"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out << "THIS IS A PLASMOID SCRIPT....."; @@ -104,8 +100,8 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName) // files to it for test purposes. // Create the images dir. - QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName + "/contents/images")); - file.setFileName(mPackageRoot + "/" + packageName + "/contents/images/image-1.svg"); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + packageName + "/contents/images")); + file.setFileName(m_packageRoot + "/" + packageName + "/contents/images/image-1.svg"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); @@ -113,7 +109,7 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName) file.flush(); file.close(); - file.setFileName(mPackageRoot + "/" + packageName + "/contents/images/image-2.svg"); + file.setFileName(m_packageRoot + "/" + packageName + "/contents/images/image-2.svg"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); @@ -125,7 +121,8 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName) void PlasmoidPackageTest::isValid() { - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + Plasma::Package *p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); // A PlasmoidPackage is valid when: // - The package root exists. @@ -133,16 +130,17 @@ void PlasmoidPackageTest::isValid() QVERIFY(!p->isValid()); // Create the root and package dir. - QVERIFY(QDir().mkpath(mPackageRoot)); - QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage)); + QVERIFY(QDir().mkpath(m_packageRoot)); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package)); // Should still be invalid. delete p; - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); QVERIFY(!p->isValid()); // Create the metadata.desktop file. - QFile file(mPackageRoot + "/" + mPackage + "/metadata.desktop"); + QFile file(m_packageRoot + "/" + m_package + "/metadata.desktop"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&file); @@ -153,15 +151,16 @@ void PlasmoidPackageTest::isValid() file.close(); // Create the code dir. - QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage + "/contents/code")); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package + "/contents/code")); // No main file yet so should still be invalid. delete p; - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); QVERIFY(!p->isValid()); // Create the main file. - file.setFileName(mPackageRoot + "/" + mPackage + "/contents/code/main"); + file.setFileName(m_packageRoot + "/" + m_package + "/contents/code/main"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); out.setDevice(&file); @@ -172,9 +171,11 @@ void PlasmoidPackageTest::isValid() file.setPermissions(QFile::ReadUser | QFile::WriteUser); // Main file exists so should be valid now. delete p; - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); QVERIFY(p->isValid()); QCOMPARE(p->contentsHash(), QString("db0b38c2b4fe21a9f37923cc25152340de055f6d")); + delete p; } void PlasmoidPackageTest::filePath() @@ -182,12 +183,13 @@ void PlasmoidPackageTest::filePath() // Package::filePath() returns // - {package_root}/{package_name}/path/to/file if the file exists // - QString() otherwise. - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + Plasma::Package *p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); QCOMPARE(p->filePath("scripts", "main"), QString()); - QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage + "/contents/code")); - QFile file(mPackageRoot + "/" + mPackage + "/contents/code/main"); + QVERIFY(QDir().mkpath(m_packageRoot + "/" + m_package + "/contents/code")); + QFile file(m_packageRoot + "/" + m_package + "/contents/code/main"); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&file); @@ -197,9 +199,10 @@ void PlasmoidPackageTest::filePath() // The package is valid by now so a path for code/main should get returned. delete p; - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); + p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); - const QString path = KStandardDirs::realFilePath(mPackageRoot + "/" + mPackage + "/contents/code/main"); + const QString path = KStandardDirs::realFilePath(m_packageRoot + "/" + m_package + "/contents/code/main"); // Two ways to get the same info. // 1. Give the file type which refers to a class of files (a directory) in @@ -210,17 +213,17 @@ void PlasmoidPackageTest::filePath() // specific for a PlasmoidPackage. QCOMPARE(p->filePath("scripts", "main"), path); QCOMPARE(p->filePath("mainscript"), path); + delete p; } void PlasmoidPackageTest::entryList() { - QString packageName("SomePlasmoid"); - // Create a package named @p packageName which is valid and has some images. - createTestPackage(packageName); + createTestPackage("SomePlasmoid"); // Create a package object and verify that it is valid. - p = new Plasma::Package(mPackageRoot + '/' + packageName, ps); + Plasma::Package *p = new Plasma::Package(m_defaultPackage); + p->setPath(m_packageRoot + '/' + m_package); QVERIFY(p->isValid()); // Now we have a valid package that should contain the following files in @@ -236,56 +239,14 @@ void PlasmoidPackageTest::entryList() QCOMPARE(files.size(), 2); QVERIFY(files.contains("image-1.svg")); QVERIFY(files.contains("image-2.svg")); -} - -void PlasmoidPackageTest::knownPackages() -{ - // Don't do strange things when package root doesn't exists. - QDir pRoot = QDir(mPackageRoot + "blah"); - QVERIFY(!pRoot.exists()); - p = new Plasma::Package(mPackageRoot + "blah/" + mPackage, ps); - QCOMPARE(Plasma::Package::listInstalled(mPackageRoot), QStringList()); delete p; - - // Don't do strange things when an empty package root exists - QVERIFY(QDir().mkpath(mPackageRoot)); - //QVERIFY(pRoot.exists()); - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); - QCOMPARE(Plasma::Package::listInstalled(mPackageRoot), QStringList()); - delete p; - - // Do not return a directory as package if it has no metadata.desktop file - QVERIFY(QDir().mkpath(mPackageRoot + "/invalid_plasmoid")); - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); - QCOMPARE(Plasma::Package::listInstalled(mPackageRoot), QStringList()); - delete p; - - // Let's add a valid package and see what happens. - QString plamoid1("a_valid_plasmoid"); - createTestPackage(plamoid1); - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); - - QStringList packages = Plasma::Package::listInstalled(mPackageRoot); - QCOMPARE(packages.size(), 1); - QVERIFY(packages.contains(plamoid1)); - - // Ok.... one more valid package. - QString plamoid2("another_valid_plasmoid"); - createTestPackage(plamoid2); - p = new Plasma::Package(mPackageRoot + '/' + mPackage, ps); - - packages = Plasma::Package::listInstalled(mPackageRoot); - QCOMPARE(packages.size(), 2); - QVERIFY(packages.contains(plamoid1)); - QVERIFY(packages.contains(plamoid2)); } void PlasmoidPackageTest::createAndInstallPackage() { - QString plasmoid("plasmoid_to_package"); - createTestPackage(plasmoid); + createTestPackage("plasmoid_to_package"); - const QString packagePath = mPackageRoot + '/' + "testpackage.plasmoid"; + const QString packagePath = m_packageRoot + '/' + "testpackage.plasmoid"; KZip creator(packagePath); creator.addLocalDirectory(packagePath, "."); @@ -301,19 +262,19 @@ void PlasmoidPackageTest::createAndInstallPackage() const KArchiveEntry *contentsEntry = dir->entry("contents"); QVERIFY(contentsEntry); QVERIFY(contentsEntry->isDirectory()); - const KArchiveDirectory *contents = - static_cast(contentsEntry); + const KArchiveDirectory *contents = static_cast(contentsEntry); QVERIFY(contents->entry("code")); QVERIFY(contents->entry("images")); - Plasma::PackageStructure::Ptr plasmoidStructure(Plasma::Applet::packageStructure()); - QVERIFY(plasmoidStructure->installPackage(packagePath, mPackageRoot)); - QString installedPackage = mPackageRoot + "/test"; + Plasma::Package *p = new Plasma::Package(m_defaultPackage); + QVERIFY(p->installPackage(packagePath, m_packageRoot)); + QString installedPackage = m_packageRoot + "/test"; QVERIFY(QFile::exists(installedPackage)); - p = new Plasma::Package(installedPackage, ps); + p->setPath(installedPackage); QVERIFY(p->isValid()); + delete p; } QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI) diff --git a/tests/plasmoidpackagetest.h b/tests/plasmoidpackagetest.h index 1b4a5e0a1..04a78bc81 100644 --- a/tests/plasmoidpackagetest.h +++ b/tests/plasmoidpackagetest.h @@ -35,17 +35,15 @@ private Q_SLOTS: void isValid(); void filePath(); void entryList(); - void knownPackages(); void createAndInstallPackage(); private: void removeDir(const QString &subdir); void createTestPackage(const QString &packageName); - QString mPackageRoot; - QString mPackage; - Plasma::PackageStructure::Ptr ps; - Plasma::Package *p; + QString m_packageRoot; + QString m_package; + Plasma::Package m_defaultPackage; }; #endif diff --git a/tests/signingtest.cpp b/tests/signingtest.cpp index 2fb95dadb..ad96f354a 100644 --- a/tests/signingtest.cpp +++ b/tests/signingtest.cpp @@ -31,8 +31,9 @@ static const QString fingerprint("8B8B22090C6F7C47B1EAEE75D6B72EB1A7F1DB43"); SigningTest::SigningTest(QObject *parent) : QObject(parent), m_signing(0), - m_package(QString::fromLatin1(KDESRCDIR) + "signedPackage", Plasma::Applet::packageStructure()) + m_package(Plasma::Package::load("Plasma/Applet")) { + m_package.setPath(QString::fromLatin1(KDESRCDIR) + "signedPackage"); const QString prefix = QString::fromLatin1(KDESRCDIR); m_path = prefix + "signed.plasmoid"; m_sig = prefix + "signed.plasmoid.sig";