- Added some tests for Package::knownPackages.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=734732
This commit is contained in:
parent
bcf898ca7b
commit
0c17b03543
@ -35,7 +35,11 @@ void PlasmoidPackageTest::init()
|
|||||||
void PlasmoidPackageTest::cleanup()
|
void PlasmoidPackageTest::cleanup()
|
||||||
{
|
{
|
||||||
delete ps;
|
delete ps;
|
||||||
delete p;
|
if( p )
|
||||||
|
{
|
||||||
|
delete p;
|
||||||
|
p = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Clean things up.
|
// Clean things up.
|
||||||
QDir local = QDir::homePath() + QLatin1String("/.kde-unit-test/packageRoot/");
|
QDir local = QDir::homePath() + QLatin1String("/.kde-unit-test/packageRoot/");
|
||||||
@ -65,8 +69,14 @@ void PlasmoidPackageTest::removeDir(const QString &subdir)
|
|||||||
|
|
||||||
void PlasmoidPackageTest::createTestPackage(const QString &packageName)
|
void PlasmoidPackageTest::createTestPackage(const QString &packageName)
|
||||||
{
|
{
|
||||||
|
QDir pRoot(mPackageRoot);
|
||||||
// Create the root and package dir.
|
// Create the root and package dir.
|
||||||
QVERIFY(QDir().mkpath(mPackageRoot));
|
if(!pRoot.exists())
|
||||||
|
{
|
||||||
|
QVERIFY(QDir().mkpath(mPackageRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the package dir
|
||||||
QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName));
|
QVERIFY(QDir().mkpath(mPackageRoot + "/" + packageName));
|
||||||
|
|
||||||
// Create the metadata.desktop file
|
// Create the metadata.desktop file
|
||||||
@ -77,6 +87,7 @@ void PlasmoidPackageTest::createTestPackage(const QString &packageName)
|
|||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
out << "[Desktop Entry]\n";
|
out << "[Desktop Entry]\n";
|
||||||
out << "Name=" << packageName << "\n";
|
out << "Name=" << packageName << "\n";
|
||||||
|
out << "X-KDE-PluginInfo-Name=" << packageName << "\n";
|
||||||
file.flush();
|
file.flush();
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@ -225,4 +236,46 @@ void PlasmoidPackageTest::entryList()
|
|||||||
QVERIFY(files.contains("image-2.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);
|
||||||
|
QVERIFY(!pRoot.exists());
|
||||||
|
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||||
|
QCOMPARE(p->knownPackages(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(p->knownPackages(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(p->knownPackages(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 = p->knownPackages(mPackageRoot);
|
||||||
|
QCOMPARE(packages.size(), 1);
|
||||||
|
QVERIFY(packages.contains(plamoid1));
|
||||||
|
|
||||||
|
// Ok.... one more valid package.
|
||||||
|
QString plamoid2("anoter_valid_plasmoid");
|
||||||
|
createTestPackage(plamoid2);
|
||||||
|
p = new Plasma::Package(mPackageRoot, mPackage, *ps);
|
||||||
|
|
||||||
|
packages = p->knownPackages(mPackageRoot);
|
||||||
|
QCOMPARE(packages.size(), 2);
|
||||||
|
QVERIFY(packages.contains(plamoid1));
|
||||||
|
QVERIFY(packages.contains(plamoid2));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI)
|
QTEST_KDEMAIN(PlasmoidPackageTest, NoGUI)
|
||||||
|
@ -35,6 +35,7 @@ private Q_SLOTS:
|
|||||||
void isValid();
|
void isValid();
|
||||||
void filePath();
|
void filePath();
|
||||||
void entryList();
|
void entryList();
|
||||||
|
void knownPackages();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void removeDir(const QString &subdir);
|
void removeDir(const QString &subdir);
|
||||||
|
Loading…
Reference in New Issue
Block a user