~ubuntu-branches/ubuntu/oneiric/kde4libs/oneiric-proposed

« back to all changes in this revision

Viewing changes to kio/tests/kdirmodeltest.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:08:34 UTC
  • mto: This revision was merged to the branch mainline in revision 247.
  • Revision ID: package-import@ubuntu.com-20110708000834-dr9a8my4iml90qe5
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
    QVERIFY(!fileItem.isNull());
304
304
    QCOMPARE(fileItem.name(), QString("toplevelfile_1"));
305
305
    QVERIFY(!fileItem.isDir());
306
 
    QCOMPARE(fileItem.url().path(), m_tempDir->name() + "toplevelfile_1");
 
306
    QCOMPARE(fileItem.url().path(), QString(m_tempDir->name() + "toplevelfile_1"));
307
307
 
308
308
    KFileItem dirItem = m_dirModel->itemForIndex(m_dirIndex);
309
309
    QVERIFY(!dirItem.isNull());
310
310
    QCOMPARE(dirItem.name(), QString("subdir"));
311
311
    QVERIFY(dirItem.isDir());
312
 
    QCOMPARE(dirItem.url().path(), m_tempDir->name() + "subdir");
 
312
    QCOMPARE(dirItem.url().path(), QString(m_tempDir->name() + "subdir"));
313
313
 
314
314
    KFileItem fileInDirItem = m_dirModel->itemForIndex(m_fileInDirIndex);
315
315
    QVERIFY(!fileInDirItem.isNull());
316
316
    QCOMPARE(fileInDirItem.name(), QString("testfile"));
317
317
    QVERIFY(!fileInDirItem.isDir());
318
 
    QCOMPARE(fileInDirItem.url().path(), m_tempDir->name() + "subdir/testfile");
 
318
    QCOMPARE(fileInDirItem.url().path(), QString(m_tempDir->name() + "subdir/testfile"));
319
319
 
320
320
    KFileItem fileInSubdirItem = m_dirModel->itemForIndex(m_fileInSubdirIndex);
321
321
    QVERIFY(!fileInSubdirItem.isNull());
322
322
    QCOMPARE(fileInSubdirItem.name(), QString("testfile"));
323
323
    QVERIFY(!fileInSubdirItem.isDir());
324
 
    QCOMPARE(fileInSubdirItem.url().path(), m_tempDir->name() + "subdir/subsubdir/testfile");
 
324
    QCOMPARE(fileInSubdirItem.url().path(), QString(m_tempDir->name() + "subdir/subsubdir/testfile"));
325
325
}
326
326
 
327
327
void KDirModelTest::testIndexForItem()
500
500
    disconnect(m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
501
501
               &m_eventLoop, SLOT(exitLoop()));
502
502
 
503
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir").isValid());
504
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir_renamed").isValid());
 
503
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir")).isValid());
 
504
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir_renamed")).isValid());
505
505
 
506
506
    connect(m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
507
507
            &m_eventLoop, SLOT(exitLoop()));
556
556
    // check renaming happened
557
557
    QCOMPARE(m_dirModel->itemForIndex(m_dirIndex).url().url(), newUrl.url());
558
558
    QCOMPARE(m_dirModel->indexForUrl(newUrl), m_dirIndex);
559
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir_renamed").isValid());
560
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir_renamed/testfile").isValid());
561
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir_renamed/subsubdir").isValid());
562
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir_renamed/subsubdir/testfile").isValid());
 
559
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir_renamed")).isValid());
 
560
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/testfile")).isValid());
 
561
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/subsubdir")).isValid());
 
562
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/subsubdir/testfile")).isValid());
563
563
 
564
564
    // Check the other kdirmodel got redirected
565
 
    QCOMPARE(dirListerForExpand->url().path(), path+"subdir_renamed");
 
565
    QCOMPARE(dirListerForExpand->url().path(), QString(path+"subdir_renamed"));
566
566
 
567
567
    kDebug() << "calling testMoveDirectory(subdir_renamed)";
568
568
 
582
582
 
583
583
    QCOMPARE(m_dirModel->itemForIndex(m_dirIndex).url().url(), url.url());
584
584
    QCOMPARE(m_dirModel->indexForUrl(url), m_dirIndex);
585
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir").isValid());
586
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir/testfile").isValid());
587
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir/subsubdir").isValid());
588
 
    QVERIFY(m_dirModel->indexForUrl(path + "subdir/subsubdir/testfile").isValid());
589
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir_renamed").isValid());
590
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir_renamed/testfile").isValid());
591
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir_renamed/subsubdir").isValid());
592
 
    QVERIFY(!m_dirModel->indexForUrl(path + "subdir_renamed/subsubdir/testfile").isValid());
 
585
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir")).isValid());
 
586
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir/testfile")).isValid());
 
587
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir/subsubdir")).isValid());
 
588
    QVERIFY(m_dirModel->indexForUrl(KUrl(path + "subdir/subsubdir/testfile")).isValid());
 
589
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir_renamed")).isValid());
 
590
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/testfile")).isValid());
 
591
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/subsubdir")).isValid());
 
592
    QVERIFY(!m_dirModel->indexForUrl(KUrl(path + "subdir_renamed/subsubdir/testfile")).isValid());
593
593
 
594
594
    // TODO INVESTIGATE
595
595
    // QCOMPARE(dirListerForExpand->url().path(), path+"subdir");
739
739
    const QString path = m_tempDir->name();
740
740
    if (flags & CacheSubdir) {
741
741
        // This way, the listDir for subdir will find items in cache, and will schedule a CachedItemsJob
742
 
        m_dirModel->dirLister()->openUrl(path + "subdir");
 
742
        m_dirModel->dirLister()->openUrl(KUrl(path + "subdir"));
743
743
        QTest::kWaitForSignal(m_dirModel->dirLister(), SIGNAL(completed()), 2000);
744
744
    }
745
745
    if (flags & ListFinalDir) {
746
746
        // This way, the last listDir will find items in cache, and will schedule a CachedItemsJob
747
 
        m_dirModel->dirLister()->openUrl(path + "subdir/subsubdir");
 
747
        m_dirModel->dirLister()->openUrl(KUrl(path + "subdir/subsubdir"));
748
748
        QTest::kWaitForSignal(m_dirModel->dirLister(), SIGNAL(completed()), 2000);
749
749
    }
750
750
 
803
803
    KFileItem item = m_dirModelForExpand->itemForIndex(index);
804
804
    QVERIFY(!item.isNull());
805
805
    kDebug() << item.url().path();
806
 
    QCOMPARE(item.url().path(), path + m_expectedExpandSignals[m_nextExpectedExpandSignals++]);
 
806
    QCOMPARE(item.url().path(), QString(path + m_expectedExpandSignals[m_nextExpectedExpandSignals++]));
807
807
 
808
808
    // if rowsInserted wasn't emitted yet, then any proxy model would be unable to do anything with index at this point
809
809
    if (item.url() == m_urlToExpandTo) {
965
965
    QModelIndex index = m_dirModel->indexForUrl(KUrl(path+"subdir//testfile"));
966
966
    QVERIFY(index.isValid());
967
967
 
968
 
    index = m_dirModel->indexForUrl(path+"subdir//subsubdir//");
 
968
    index = m_dirModel->indexForUrl(KUrl(path+"subdir//subsubdir//"));
969
969
    QVERIFY(index.isValid());
970
970
 
971
 
    index = m_dirModel->indexForUrl(path+"subdir///subsubdir////testfile");
 
971
    index = m_dirModel->indexForUrl(KUrl(path+"subdir///subsubdir////testfile"));
972
972
    QVERIFY(index.isValid());
973
973
}
974
974
 
1066
1066
    }
1067
1067
}
1068
1068
 
 
1069
class MyDirLister : public KDirLister
 
1070
{
 
1071
public:
 
1072
    void emitItemsDeleted(const KFileItemList& items) { emit itemsDeleted(items); }
 
1073
};
 
1074
 
 
1075
void KDirModelTest::testBug196695()
 
1076
{
 
1077
    KFileItem rootItem(KUrl(m_tempDir->name()), QString(), KFileItem::Unknown);
 
1078
    KFileItem childItem(KUrl(QString(m_tempDir->name() + "toplevelfile_1")), QString(), KFileItem::Unknown);
 
1079
 
 
1080
    KFileItemList list;
 
1081
    // Important: the root item must not be first in the list to trigger bug 196695
 
1082
    list << childItem << rootItem;
 
1083
 
 
1084
    MyDirLister* dirLister = static_cast<MyDirLister*>(m_dirModel->dirLister());
 
1085
    dirLister->emitItemsDeleted(list);
 
1086
 
 
1087
    fillModel(true);
 
1088
}
 
1089
 
1069
1090
void KDirModelTest::testDeleteFile()
1070
1091
{
1071
1092
    fillModel(false);
1095
1116
    disconnect( m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1096
1117
                &m_eventLoop, SLOT(exitLoop()) );
1097
1118
 
1098
 
    QModelIndex fileIndex = m_dirModel->indexForUrl(path + "toplevelfile_1");
 
1119
    QModelIndex fileIndex = m_dirModel->indexForUrl(KUrl(path + "toplevelfile_1"));
1099
1120
    QVERIFY(!fileIndex.isValid());
1100
1121
 
1101
1122
    // Recreate the file, for consistency in the next tests
1138
1159
    QCOMPARE(spyRowsRemoved[0][1].toInt(), m_fileIndex.row());
1139
1160
    QCOMPARE(spyRowsRemoved[0][2].toInt(), m_fileIndex.row());
1140
1161
 
1141
 
    QModelIndex fileIndex = m_dirModel->indexForUrl(path + "toplevelfile_1");
 
1162
    QModelIndex fileIndex = m_dirModel->indexForUrl(KUrl(path + "toplevelfile_1"));
1142
1163
    QVERIFY(!fileIndex.isValid());
1143
1164
 
1144
1165
    kDebug() << "Test done, recreating file";
1181
1202
    QCOMPARE(topLevelRowCount, oldTopLevelRowCount - 1); // one less than before
1182
1203
 
1183
1204
    QVERIFY(!m_dirModel->indexForUrl(dir).isValid());
1184
 
    QModelIndex newIndex = m_dirModel->indexForUrl(path + "toplevelfile_1");
 
1205
    QModelIndex newIndex = m_dirModel->indexForUrl(KUrl(path + "toplevelfile_1"));
1185
1206
    QVERIFY(newIndex.isValid());
1186
1207
    KFileItem newItem = m_dirModel->itemForIndex(newIndex);
1187
1208
    QVERIFY(newItem.isDir()); // yes, the file is a dir now ;-)
1292
1313
    disconnect( m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1293
1314
                &m_eventLoop, SLOT(exitLoop()) );
1294
1315
 
1295
 
    QModelIndex deletedDirIndex = m_dirModel->indexForUrl(path + "subdir/subsubdir");
 
1316
    QModelIndex deletedDirIndex = m_dirModel->indexForUrl(KUrl(path + "subdir/subsubdir"));
1296
1317
    QVERIFY(!deletedDirIndex.isValid());
1297
 
    QModelIndex dirIndex = m_dirModel->indexForUrl(path + "subdir");
 
1318
    QModelIndex dirIndex = m_dirModel->indexForUrl(KUrl(path + "subdir"));
1298
1319
    QVERIFY(dirIndex.isValid());
1299
1320
 
1300
1321
    // TODO!!! Bug in KDirWatch? ###
1343
1364
    disconnect( m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
1344
1365
                &m_eventLoop, SLOT(exitLoop()) );
1345
1366
 
1346
 
    QModelIndex fileIndex = m_dirModel->indexForUrl(path + "toplevelfile_1");
 
1367
    QModelIndex fileIndex = m_dirModel->indexForUrl(KUrl(path + "toplevelfile_1"));
1347
1368
    QVERIFY(!fileIndex.isValid());
1348
1369
}
1349
1370