135 #endif |
135 #endif |
136 |
136 |
137 void drives_data(); |
137 void drives_data(); |
138 void drives(); |
138 void drives(); |
139 void dirsBeforeFiles(); |
139 void dirsBeforeFiles(); |
|
140 |
|
141 void roleNames_data(); |
|
142 void roleNames(); |
|
143 |
140 protected: |
144 protected: |
141 bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList(), const QString &baseDir = QDir::temp().absolutePath()); |
145 bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList(), const QString &baseDir = QDir::temp().absolutePath()); |
142 |
146 |
143 private: |
147 private: |
144 QFileSystemModel *model; |
148 QFileSystemModel *model; |
234 |
238 |
235 QTRY_VERIFY(model->rowCount(root) >= 0); |
239 QTRY_VERIFY(model->rowCount(root) >= 0); |
236 QCOMPARE(model->rootPath(), QString(QDir::homePath())); |
240 QCOMPARE(model->rootPath(), QString(QDir::homePath())); |
237 QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1); |
241 QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1); |
238 QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath()); |
242 QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath()); |
|
243 |
|
244 model->setRootPath(QDir::rootPath()); |
|
245 int oldCount = rootChanged.count(); |
|
246 oldRootPath = model->rootPath(); |
|
247 root = model->setRootPath(QDir::homePath() + QLatin1String("/.")); |
|
248 QTRY_VERIFY(model->rowCount(root) >= 0); |
|
249 QCOMPARE(model->rootPath(), QDir::homePath()); |
|
250 QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1); |
|
251 QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath()); |
|
252 |
|
253 QDir newdir = QDir::home(); |
|
254 if (newdir.cdUp()) { |
|
255 oldCount = rootChanged.count(); |
|
256 oldRootPath = model->rootPath(); |
|
257 root = model->setRootPath(QDir::homePath() + QLatin1String("/..")); |
|
258 QTRY_VERIFY(model->rowCount(root) >= 0); |
|
259 QCOMPARE(model->rootPath(), newdir.path()); |
|
260 QCOMPARE(rootChanged.count(), oldCount + 1); |
|
261 QCOMPARE(model->rootDirectory().absolutePath(), newdir.path()); |
|
262 } |
239 } |
263 } |
240 |
264 |
241 void tst_QFileSystemModel::naturalCompare_data() |
265 void tst_QFileSystemModel::naturalCompare_data() |
242 { |
266 { |
243 QTest::addColumn<QString>("s1"); |
267 QTest::addColumn<QString>("s1"); |
994 model->fileInfo(model->index(i, 0, root)).fileName()); |
1018 model->fileInfo(model->index(i, 0, root)).fileName()); |
995 #endif |
1019 #endif |
996 } |
1020 } |
997 } |
1021 } |
998 |
1022 |
|
1023 void tst_QFileSystemModel::roleNames_data() |
|
1024 { |
|
1025 QTest::addColumn<int>("role"); |
|
1026 QTest::addColumn<QByteArray>("roleName"); |
|
1027 QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration"); |
|
1028 QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display"); |
|
1029 QTest::newRow("fileIcon") << int(QFileSystemModel::FileIconRole) << QByteArray("fileIcon"); |
|
1030 QTest::newRow("filePath") << int(QFileSystemModel::FilePathRole) << QByteArray("filePath"); |
|
1031 QTest::newRow("fileName") << int(QFileSystemModel::FileNameRole) << QByteArray("fileName"); |
|
1032 QTest::newRow("filePermissions") << int(QFileSystemModel::FilePermissions) << QByteArray("filePermissions"); |
|
1033 } |
|
1034 |
|
1035 void tst_QFileSystemModel::roleNames() |
|
1036 { |
|
1037 QFileSystemModel model; |
|
1038 QHash<int, QByteArray> roles = model.roleNames(); |
|
1039 |
|
1040 QFETCH(int, role); |
|
1041 QVERIFY(roles.contains(role)); |
|
1042 |
|
1043 QFETCH(QByteArray, roleName); |
|
1044 QList<QByteArray> values = roles.values(role); |
|
1045 QVERIFY(values.contains(roleName)); |
|
1046 } |
|
1047 |
999 QTEST_MAIN(tst_QFileSystemModel) |
1048 QTEST_MAIN(tst_QFileSystemModel) |
1000 #include "tst_qfilesystemmodel.moc" |
1049 #include "tst_qfilesystemmodel.moc" |
1001 |
1050 |