diff --git a/package.cpp b/package.cpp index 1cca067ff..30a2f6e6a 100644 --- a/package.cpp +++ b/package.cpp @@ -104,8 +104,9 @@ QString Package::filePath(const char* fileType, const QString& filename) const return QString(); } + path.prepend(d->basePath); + if (!filename.isEmpty()) { - path.prepend(d->basePath); path.append("/").append(filename); } diff --git a/tests/plasmoidpackagetest.cpp b/tests/plasmoidpackagetest.cpp index 0aaf168e9..5427ce582 100644 --- a/tests/plasmoidpackagetest.cpp +++ b/tests/plasmoidpackagetest.cpp @@ -72,7 +72,6 @@ void PlasmoidPackageTest::isValid() // Should still be invalid. delete p; p = new Plasma::Package(mPackageRoot, mPackage, *ps); - qDebug() << p->isValid(); QVERIFY(!p->isValid()); // Create the code dir. @@ -98,4 +97,41 @@ void PlasmoidPackageTest::isValid() QVERIFY(p->isValid()); } +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()); + + QVERIFY(QDir().mkpath(mPackageRoot + "/" + mPackage + "/code")); + QFile file(mPackageRoot + "/" + mPackage + "/code/main"); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + + QTextStream out(&file); + out << "THIS IS A PLASMOID SCRIPT....."; + file.flush(); + file.close(); + + // The package is valid by now so a path for code/main should get returned. + delete p; + p = new Plasma::Package(mPackageRoot, mPackage, *ps); + + QString path = mPackageRoot + "/" + mPackage + "/code/main"; + + // Two ways to get the same info. + // 1. Give the file type which refers to a class of files (a directory) in + // the package strucutre and the file name. + // 2. Give the file type which refers to a file in the package structure. + // + // NOTE: scripts, main and mainscript are defined in packages.cpp and are + // specific for a PlasmoidPackag. + QCOMPARE(p->filePath("scripts", "main"), path); + QCOMPARE(p->filePath("mainscript"), path); +} + QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI) diff --git a/tests/plasmoidpackagetest.h b/tests/plasmoidpackagetest.h index ef86004e5..267657ea9 100644 --- a/tests/plasmoidpackagetest.h +++ b/tests/plasmoidpackagetest.h @@ -33,6 +33,7 @@ public Q_SLOTS: private Q_SLOTS: void isValid(); + void filePath(); private: void removeDir(const QString &subdir);