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 << "";
+ file.flush();
+ file.close();
+
+ file.setFileName(mPackageRoot + "/" + packageName + "/images/image-2.svg");
+
+ QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text));
+
+ out.setDevice(&file);
+ out << "";
+ 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;