void tst_QDirModel::rmdir() { QFETCH(QString, dirName); QFETCH(bool, rmdirSuccess); QFETCH(int, rowCount); QDirModel model; model.setReadOnly(false); QModelIndex parent = model.index(SRCDIR "/dirtest"); QVERIFY(parent.isValid()); QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot QModelIndex index; if (rmdirSuccess) { index = model.mkdir(parent, dirName); QVERIFY(index.isValid()); } int rows = model.rowCount(parent); bool success = model.rmdir(index); if (!success) { // cleanup QDir dirtests(SRCDIR "/dirtests/"); dirtests.rmdir(dirName); } QCOMPARE(rows, rowCount); QCOMPARE(success, rmdirSuccess); }
void tst_QDirModel::rowsAboutToBeRemoved() { QFETCH(QString, test_path); QFETCH(QStringList, initial_files); QFETCH(int, remove_row); QFETCH(QStringList, remove_files); QFETCH(QStringList, expected_files); rowsAboutToBeRemoved_cleanup(test_path); // clean up first QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files)); QDirModel model; model.setReadOnly(false); qRegisterMetaType<QModelIndex>("QModelIndex"); // NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory, // and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for // rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged())); QModelIndex parent = model.index(test_path); QVERIFY(parent.isValid()); // remove the file { QModelIndex index = model.index(remove_row, 0, parent); QVERIFY(index.isValid()); QVERIFY(model.remove(index)); } QCOMPARE(spy.count(), 1); // Compare the result for (int row = 0; row < expected_files.count(); ++row) { QModelIndex index = model.index(row, 0, parent); QString str = index.data().toString(); QCOMPARE(str, expected_files.at(row)); } QVERIFY(rowsAboutToBeRemoved_cleanup(test_path)); }
void tst_QDirModel::mkdir() { QFETCH(QString, dirName); QFETCH(bool, mkdirSuccess); QFETCH(int, rowCount); QDirModel model; model.setReadOnly(false); QModelIndex parent = model.index(SRCDIR "dirtest"); QVERIFY(parent.isValid()); QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot QModelIndex index = model.mkdir(parent, dirName); bool success = index.isValid(); int rows = model.rowCount(parent); if (success && !model.rmdir(index)) QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName)); QCOMPARE(rows, rowCount); QCOMPARE(success, mkdirSuccess); }
void tst_QDirModel::task244669_remove() { QFile f1(SRCDIR "dirtest/f1.txt"); QVERIFY(f1.open(QIODevice::WriteOnly)); f1.close(); QFile f2(SRCDIR "dirtest/f2.txt"); QVERIFY(f2.open(QIODevice::WriteOnly)); f2.close(); QDirModel model; model.setReadOnly(false); QPersistentModelIndex parent = model.index(SRCDIR "dirtest"); QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt"); QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt"); QVERIFY(parent.isValid()); QVERIFY(index1.isValid()); QVERIFY(index2.isValid()); QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data()); QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data()); QVERIFY(model.remove(index1)); QVERIFY(parent.isValid()); QVERIFY(!index1.isValid()); QVERIFY(index2.isValid()); QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data()); QVERIFY(model.remove(index2)); QVERIFY(parent.isValid()); QVERIFY(!index2.isValid()); QVERIFY(!index1.isValid()); QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); }