tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp	Wed Jun 23 19:07:03 2010 +0300
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp	Tue Jul 06 15:10:48 2010 +0300
@@ -137,6 +137,10 @@
     void drives_data();
     void drives();
     void dirsBeforeFiles();
+
+    void roleNames_data();
+    void roleNames();
+
 protected:
     bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList(), const QString &baseDir = QDir::temp().absolutePath());
 
@@ -236,6 +240,26 @@
     QCOMPARE(model->rootPath(), QString(QDir::homePath()));
     QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1);
     QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath());
+
+    model->setRootPath(QDir::rootPath());
+    int oldCount = rootChanged.count();
+    oldRootPath = model->rootPath();
+    root = model->setRootPath(QDir::homePath() + QLatin1String("/."));
+    QTRY_VERIFY(model->rowCount(root) >= 0);
+    QCOMPARE(model->rootPath(), QDir::homePath());
+    QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1);
+    QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath());
+
+    QDir newdir = QDir::home();
+    if (newdir.cdUp()) {
+        oldCount = rootChanged.count();
+        oldRootPath = model->rootPath();
+        root = model->setRootPath(QDir::homePath() + QLatin1String("/.."));
+        QTRY_VERIFY(model->rowCount(root) >= 0);
+        QCOMPARE(model->rootPath(), newdir.path());
+        QCOMPARE(rootChanged.count(), oldCount + 1);
+        QCOMPARE(model->rootDirectory().absolutePath(), newdir.path());
+    }
 }
 
 void tst_QFileSystemModel::naturalCompare_data()
@@ -996,6 +1020,31 @@
     }
 }
 
+void tst_QFileSystemModel::roleNames_data()
+{
+    QTest::addColumn<int>("role");
+    QTest::addColumn<QByteArray>("roleName");
+    QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration");
+    QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display");
+    QTest::newRow("fileIcon") << int(QFileSystemModel::FileIconRole) << QByteArray("fileIcon");
+    QTest::newRow("filePath") << int(QFileSystemModel::FilePathRole) << QByteArray("filePath");
+    QTest::newRow("fileName") << int(QFileSystemModel::FileNameRole) << QByteArray("fileName");
+    QTest::newRow("filePermissions") << int(QFileSystemModel::FilePermissions) << QByteArray("filePermissions");
+}
+
+void tst_QFileSystemModel::roleNames()
+{
+    QFileSystemModel model;
+    QHash<int, QByteArray> roles = model.roleNames();
+
+    QFETCH(int, role);
+    QVERIFY(roles.contains(role));
+
+    QFETCH(QByteArray, roleName);
+    QList<QByteArray> values = roles.values(role);
+    QVERIFY(values.contains(roleName));
+}
+
 QTEST_MAIN(tst_QFileSystemModel)
 #include "tst_qfilesystemmodel.moc"