diff --git a/keditfiletype/tests/filetypestest.cpp b/keditfiletype/tests/filetypestest.cpp --- a/keditfiletype/tests/filetypestest.cpp +++ b/keditfiletype/tests/filetypestest.cpp @@ -22,6 +22,7 @@ #include #include +#include #include // Qt @@ -383,11 +384,28 @@ QVERIFY(!kbuildsycoca.isEmpty()); QStringList args; args << "--testmode"; + + // KSycoca internally will not be able to notify us of changes if this is + // the first time it is run (e.g. in isolated testbeds), so bypass KSycoca + // if it is reported not valid or we can't read the supposedly used file. + // Subsequent runs should then be able to use KSycoca directly, if not as long + // as the supposed cache file changes we should be fine either way. + QFileInfo info(KSycoca::absoluteFilePath()); + QScopedPointer watcher; + QScopedPointer spy; + if (KSycoca::isAvailable() && info.isReadable()) { + qDebug() << "spying databaseChanged signal"; + spy.reset(new QSignalSpy(KSycoca::self(), SIGNAL(databaseChanged(QStringList)))); + } else { + qDebug() << "spying dirwatch because KSycoca is not available!"; + watcher.reset(new KDirWatch); + watcher->addFile(KSycoca::absoluteFilePath()); + spy.reset(new QSignalSpy(watcher.data(), &KDirWatch::created)); + } proc.start(kbuildsycoca, args); - QSignalSpy spy(KSycoca::self(), SIGNAL(databaseChanged(QStringList))); proc.waitForFinished(); qDebug() << "waiting for signal"; - QVERIFY(spy.wait(10000)); + QVERIFY(spy->wait(10000)); qDebug() << "got signal"; }