From 6bba95aa0b426a6157fac6de8c74c49a04a68886 Mon Sep 17 00:00:00 2001 From: Bertjan Broeksema Date: Thu, 8 Nov 2007 20:27:43 +0000 Subject: [PATCH] - Added a test for the entryList method of Package. - Added a TODO list to keep track of tests which need work. Feel free to add suggestions for tests or enhancements of tests. When time permits i'll work on it. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=734422 --- tests/TODO | 38 +++++++++++++++ tests/plasmoidpackagetest.cpp | 87 ++++++++++++++++++++++++++++++++--- tests/plasmoidpackagetest.h | 4 +- 3 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 tests/TODO diff --git a/tests/TODO b/tests/TODO new file mode 100644 index 000000000..215e6fea9 --- /dev/null +++ b/tests/TODO @@ -0,0 +1,38 @@ +This file enumerates which classes and methods needs test. Please feel free to +add a specific test you'd like to see for a class/method. + +// Finished (as in has test for each method) +packagestructure + +// Work in progress. Enumerated methods don't have tests yet. +Package: + - knownPackages + - installPackage + - createPackage + +// No tests written atm. +abstractrunner +animator +appletbrowser +applet +configxml +containment +corona +datacontainer +datacontainer_p +dataengine +dataenginemanager +glapplet +package +packagemetadata +packages_p +phase +plasma_export +plasma +scriptengine +searchaction +searchcontext +shadowitem_p +svg +theme +uiloader diff --git a/tests/plasmoidpackagetest.cpp b/tests/plasmoidpackagetest.cpp index 5427ce582..50a20cf93 100644 --- a/tests/plasmoidpackagetest.cpp +++ b/tests/plasmoidpackagetest.cpp @@ -28,19 +28,24 @@ 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 local = QDir::homePath() + QLatin1String("/.kde-unit-test/packageRoot/"); + foreach(const QString &dir, local.entryList(QDir::Dirs)) + { + removeDir(QLatin1String("packageRoot/" + dir.toLatin1() + "/code")); + removeDir(QLatin1String("packageRoot/" + dir.toLatin1() + "/images")); + removeDir(QLatin1String("packageRoot/" + dir.toLatin1())); + } + QDir().rmpath(QDir::homePath() + "/.kde-unit-test/packageRoot"); } @@ -58,8 +63,52 @@ void PlasmoidPackageTest::removeDir(const QString &subdir) local.rmpath(subd); } +void PlasmoidPackageTest::createTestPackage(const QString &packageName) +{ + // Create the root and package dir. + QVERIFY(QDir().mkpath(mPackageRoot)); + QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName)); + + // Create the code dir. + QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName + "/code")); + + // Create the main file. + QFile file(mPackageRoot + "/" + packageName + "/code/main"); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + + QTextStream out(&file); + out << "THIS IS A PLASMOID SCRIPT....."; + file.flush(); + file.close(); + + // Now we have a minimal plasmoid package which is valid. Let's add some + // files to it for test purposes. + + // Create the images dir. + QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName + "/images")); + file.setFileName(mPackageRoot + "/" + packageName + "/images/image-1.svg"); + + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + + out.setDevice(&file); + out << "This is a test image"; + file.flush(); + file.close(); + + file.setFileName(mPackageRoot + "/" + packageName + "/images/image-2.svg"); + + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + + out.setDevice(&file); + out << "This is another test image"; + file.flush(); + file.close(); +} + void PlasmoidPackageTest::isValid() { + p = new Plasma::Package(mPackageRoot, mPackage, *ps); + // A PlasmoidPackage is valid when: // - The package root exists. // - The package root consists an file named "code/main" @@ -102,8 +151,6 @@ void PlasmoidPackageTest::filePath() // Package::filePath() returns // - {package_root}/{package_name}/path/to/file if the file exists // - QString() otherwise. - - delete p; p = new Plasma::Package(mPackageRoot, mPackage, *ps); QCOMPARE(p->filePath("scripts", "main"), QString()); @@ -134,4 +181,30 @@ void PlasmoidPackageTest::filePath() QCOMPARE(p->filePath("mainscript"), path); } +void PlasmoidPackageTest::entryList() +{ + QString packageName("SomePlasmoid"); + + // Create a package named @p packageName which is valid and has some images. + createTestPackage(packageName); + + // Create a package object and verify that it is valid. + p = new Plasma::Package(mPackageRoot, packageName, *ps); + QVERIFY(p->isValid()); + + // Now we have a valid package that should contain the following files in + // given filetypes: + // fileTye - Files + // scripts - {"main"} + // images - {"image-1.svg", "image-2.svg"} + QStringList files = p->entryList("scripts"); + QCOMPARE(files.size(), 1); + QVERIFY(files.contains("main")); + + files = p->entryList("images"); + QCOMPARE(files.size(), 2); + QVERIFY(files.contains("image-1.svg")); + QVERIFY(files.contains("image-2.svg")); +} + QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI) diff --git a/tests/plasmoidpackagetest.h b/tests/plasmoidpackagetest.h index 267657ea9..2871c549d 100644 --- a/tests/plasmoidpackagetest.h +++ b/tests/plasmoidpackagetest.h @@ -34,10 +34,12 @@ public Q_SLOTS: private Q_SLOTS: void isValid(); void filePath(); + void entryList(); private: void removeDir(const QString &subdir); - + void createTestPackage(const QString &packageName); + QString mPackageRoot; QString mPackage; Plasma::PackageStructure *ps;