mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
gwenview: stabilize the RecursiveDirModel test
note that this race that was observed by the author of the test will happen outside the test - if files are created while the KDirLister is listing (because an automatic update was issued for example) some files may not be listed Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c55b482da9
commit
2c90b02a32
4 changed files with 12 additions and 18 deletions
|
@ -119,6 +119,11 @@ void RecursiveDirModel::setUrl(const KUrl& url)
|
|||
d->mDirLister->openUrl(url, true);
|
||||
}
|
||||
|
||||
void RecursiveDirModel::updateDirectory()
|
||||
{
|
||||
d->mDirLister->updateDirectory();
|
||||
}
|
||||
|
||||
int RecursiveDirModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.isValid()) {
|
||||
|
@ -153,6 +158,7 @@ QVariant RecursiveDirModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
void RecursiveDirModel::slotItemsAdded(const KFileItemList& newList)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << newList;
|
||||
KFileItemList fileList;
|
||||
Q_FOREACH(const KFileItem& item, newList) {
|
||||
if (item.isFile()) {
|
||||
|
@ -173,6 +179,7 @@ void RecursiveDirModel::slotItemsAdded(const KFileItemList& newList)
|
|||
|
||||
void RecursiveDirModel::slotItemsDeleted(const KFileItemList& list)
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << list;
|
||||
Q_FOREACH(const KFileItem& item, list) {
|
||||
if (item.isDir()) {
|
||||
continue;
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
|
||||
KUrl url() const;
|
||||
void setUrl(const KUrl&);
|
||||
void updateDirectory();
|
||||
|
||||
int rowCount(const QModelIndex&) const; // reimp
|
||||
QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const; // reimp
|
||||
|
|
|
@ -138,39 +138,24 @@ void RecursiveDirModelTest::testBasic()
|
|||
|
||||
// Test adding new files
|
||||
sandBoxDir.fill(addedFiles);
|
||||
model.updateDirectory();
|
||||
loop.exec();
|
||||
|
||||
out = listModelUrls(&model);
|
||||
expected = listExpectedUrls(sandBoxDir, initialFiles + addedFiles);
|
||||
QCOMPARE(out, expected);
|
||||
|
||||
# if 0
|
||||
/* FIXME: This part of the test is not reliable :/ Sometimes some tests pass,
|
||||
* sometimes they don't. It feels like KDirLister::itemsDeleted() is not
|
||||
* always emitted.
|
||||
*/
|
||||
|
||||
// Test removing files
|
||||
Q_FOREACH(const QString &name, removedFiles) {
|
||||
bool ok = sandBoxDir.remove(name);
|
||||
Q_ASSERT(ok);
|
||||
expected.removeOne(KUrl(sandBoxDir.absoluteFilePath(name)));
|
||||
}
|
||||
QTime chrono;
|
||||
chrono.start();
|
||||
while (chrono.elapsed() < 2000) {
|
||||
waitForDeferredDeletes();
|
||||
}
|
||||
model.updateDirectory();
|
||||
loop.exec();
|
||||
|
||||
out = listModelUrls(&model);
|
||||
if (out != expected) {
|
||||
kWarning() << "out:";
|
||||
logLst(out);
|
||||
kWarning() << "expected:";
|
||||
logLst(expected);
|
||||
}
|
||||
QCOMPARE(out, expected);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RecursiveDirModelTest::testSetNewUrl()
|
||||
|
|
|
@ -155,6 +155,7 @@ void SandBoxDir::fill(const QStringList& filePaths)
|
|||
Q_FOREACH(const QString& filePath, filePaths) {
|
||||
QFileInfo info(*this, filePath);
|
||||
mkpath(info.absolutePath());
|
||||
// qDebug() << Q_FUNC_INFO << info.absoluteFilePath();
|
||||
createEmptyFile(info.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue