use non const pointers
This commit is contained in:
parent
7e73be169c
commit
6be2e9d46d
@ -28,43 +28,43 @@
|
|||||||
|
|
||||||
void FallbackPackageTest::initTestCase()
|
void FallbackPackageTest::initTestCase()
|
||||||
{
|
{
|
||||||
m_packagePath = QFINDTESTDATA("data/testpackage");
|
m_fallPackagePath = QFINDTESTDATA("data/testpackage");
|
||||||
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
|
||||||
m_pkg.setPath(m_packagePath);
|
|
||||||
|
|
||||||
m_fallPackagePath = QFINDTESTDATA("data/testfallbackpackage");
|
|
||||||
m_fallPkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
m_fallPkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
m_fallPkg.setPath(m_fallPackagePath);
|
m_fallPkg.setPath(m_fallPackagePath);
|
||||||
|
|
||||||
|
m_packagePath = QFINDTESTDATA("data/testfallbackpackage");
|
||||||
|
m_pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
|
m_pkg.setPath(m_packagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FallbackPackageTest::beforeFallback()
|
void FallbackPackageTest::beforeFallback()
|
||||||
{
|
{
|
||||||
QVERIFY(m_pkg.hasValidStructure());
|
|
||||||
QVERIFY(m_fallPkg.hasValidStructure());
|
QVERIFY(m_fallPkg.hasValidStructure());
|
||||||
|
QVERIFY(m_pkg.hasValidStructure());
|
||||||
|
|
||||||
//m_pkg should have otherfile.qml, m_fallPkg shouldn't
|
//m_fallPkg should have otherfile.qml, m_pkg shouldn't
|
||||||
QVERIFY(!m_pkg.filePath("ui", "otherfile.qml").isEmpty());
|
QVERIFY(!m_fallPkg.filePath("ui", "otherfile.qml").isEmpty());
|
||||||
QVERIFY(m_fallPkg.filePath("ui", "otherfile.qml").isEmpty());
|
QVERIFY(m_pkg.filePath("ui", "otherfile.qml").isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FallbackPackageTest::afterFallback()
|
void FallbackPackageTest::afterFallback()
|
||||||
{
|
{
|
||||||
m_fallPkg.setFallbackPackage(m_pkg);
|
m_pkg.setFallbackPackage(m_fallPkg);
|
||||||
|
|
||||||
//afetr setting the fallback, m_fallPkg should resolve the exact same file as m_pkg
|
//after setting the fallback, m_pkg should resolve the exact same file as m_fallPkg
|
||||||
// for otherfile.qml
|
// for otherfile.qml
|
||||||
QVERIFY(!m_fallPkg.filePath("ui", "otherfile.qml").isEmpty());
|
QVERIFY(!m_pkg.filePath("ui", "otherfile.qml").isEmpty());
|
||||||
QCOMPARE(m_pkg.filePath("ui", "otherfile.qml"), m_fallPkg.filePath("ui", "otherfile.qml"));
|
QCOMPARE(m_fallPkg.filePath("ui", "otherfile.qml"), m_pkg.filePath("ui", "otherfile.qml"));
|
||||||
QVERIFY(m_pkg.filePath("mainscript") != m_fallPkg.filePath("mainscript"));
|
QVERIFY(m_fallPkg.filePath("mainscript") != m_pkg.filePath("mainscript"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FallbackPackageTest::cycle()
|
void FallbackPackageTest::cycle()
|
||||||
{
|
{
|
||||||
m_pkg.setFallbackPackage(m_fallPkg);
|
|
||||||
m_fallPkg.setFallbackPackage(m_pkg);
|
m_fallPkg.setFallbackPackage(m_pkg);
|
||||||
|
m_pkg.setFallbackPackage(m_fallPkg);
|
||||||
|
|
||||||
//The cycle should have been detected and filePath should take a not infinite tiume
|
//The cycle should have been detected and filePath should take a not infinite time
|
||||||
QTRY_COMPARE_WITH_TIMEOUT(m_pkg.filePath("ui", "otherfile.qml"), m_fallPkg.filePath("ui", "otherfile.qml"), 1000);
|
QTRY_COMPARE_WITH_TIMEOUT(m_fallPkg.filePath("ui", "otherfile.qml"), m_pkg.filePath("ui", "otherfile.qml"), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(FallbackPackageTest)
|
QTEST_MAIN(FallbackPackageTest)
|
||||||
|
@ -921,13 +921,14 @@ bool PackagePrivate::hasCycle(const Plasma::Package &package)
|
|||||||
|
|
||||||
//This is the Floyd cycle detection algorithm
|
//This is the Floyd cycle detection algorithm
|
||||||
//http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare
|
//http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare
|
||||||
const Plasma::Package *slowPackage = &package;
|
Plasma::Package *slowPackage = const_cast<Plasma::Package *>(&package);
|
||||||
const Plasma::Package *fastPackage = &package;
|
Plasma::Package *fastPackage = const_cast<Plasma::Package *>(&package);
|
||||||
|
|
||||||
while (fastPackage && fastPackage->d->fallbackPackage) {
|
while (fastPackage && fastPackage->d->fallbackPackage) {
|
||||||
//consider two packages the same if they have the same metadata
|
//consider two packages the same if they have the same metadata
|
||||||
if ((fastPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->metadata() == slowPackage->metadata()) ||
|
if ((fastPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->metadata() == slowPackage->metadata()) ||
|
||||||
(fastPackage->d->fallbackPackage->d->fallbackPackage && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata() == slowPackage->metadata())) {
|
(fastPackage->d->fallbackPackage->d->fallbackPackage && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata().isValid() && fastPackage->d->fallbackPackage->d->fallbackPackage->metadata() == slowPackage->metadata())) {
|
||||||
|
qWarning() << "Warning: the fallback chain of " << package.metadata().pluginName() << "contains a cyclical dependency.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fastPackage = fastPackage->d->fallbackPackage->d->fallbackPackage;
|
fastPackage = fastPackage->d->fallbackPackage->d->fallbackPackage;
|
||||||
|
Loading…
Reference in New Issue
Block a user