author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:20:32 +0300 | |
changeset 34 | a33bf25e6f72 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qdirmodel.h> |
|
45 |
#include <qapplication.h> |
|
46 |
#include <qtreeview.h> |
|
47 |
#include <qdir.h> |
|
48 |
#include <qdebug.h> |
|
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES= |
|
52 |
||
53 |
#if defined(Q_OS_SYMBIAN) |
|
54 |
# define STRINGIFY(x) #x |
|
55 |
# define TOSTRING(x) STRINGIFY(x) |
|
56 |
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" |
|
57 |
#endif |
|
58 |
||
59 |
class tst_QDirModel : public QObject |
|
60 |
{ |
|
61 |
Q_OBJECT |
|
62 |
||
63 |
public: |
|
64 |
||
65 |
tst_QDirModel(); |
|
66 |
virtual ~tst_QDirModel(); |
|
67 |
||
68 |
||
69 |
public slots: |
|
70 |
void initTestCase(); |
|
71 |
void cleanupTestCase(); |
|
72 |
void init(); |
|
73 |
void cleanup(); |
|
74 |
private slots: |
|
75 |
void getSetCheck(); |
|
76 |
/* |
|
77 |
void construct(); |
|
78 |
void rowCount(); |
|
79 |
void columnCount(); |
|
80 |
void t_data(); |
|
81 |
void setData(); |
|
82 |
void hasChildren(); |
|
83 |
void isEditable(); |
|
84 |
void isDragEnabled(); |
|
85 |
void isDropEnabled(); |
|
86 |
void sort(); |
|
87 |
*/ |
|
88 |
bool rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files); |
|
89 |
bool rowsAboutToBeRemoved_cleanup(const QString &test_path); |
|
90 |
void rowsAboutToBeRemoved_data(); |
|
91 |
void rowsAboutToBeRemoved(); |
|
92 |
||
93 |
void mkdir_data(); |
|
94 |
void mkdir(); |
|
95 |
||
96 |
void rmdir_data(); |
|
97 |
void rmdir(); |
|
98 |
||
99 |
void filePath(); |
|
100 |
||
101 |
void hidden(); |
|
102 |
||
103 |
void fileName(); |
|
104 |
void fileName_data(); |
|
105 |
void task196768_sorting(); |
|
106 |
void filter(); |
|
107 |
||
108 |
void task244669_remove(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
109 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
110 |
void roleNames_data(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
111 |
void roleNames(); |
0 | 112 |
}; |
113 |
||
114 |
// Testing get/set functions |
|
115 |
void tst_QDirModel::getSetCheck() |
|
116 |
{ |
|
117 |
QDirModel obj1; |
|
118 |
// QFileIconProvider * QDirModel::iconProvider() |
|
119 |
// void QDirModel::setIconProvider(QFileIconProvider *) |
|
120 |
QFileIconProvider *var1 = new QFileIconProvider; |
|
121 |
obj1.setIconProvider(var1); |
|
122 |
QCOMPARE(var1, obj1.iconProvider()); |
|
123 |
obj1.setIconProvider((QFileIconProvider *)0); |
|
124 |
QCOMPARE((QFileIconProvider *)0, obj1.iconProvider()); |
|
125 |
delete var1; |
|
126 |
||
127 |
// bool QDirModel::resolveSymlinks() |
|
128 |
// void QDirModel::setResolveSymlinks(bool) |
|
129 |
obj1.setResolveSymlinks(false); |
|
130 |
QCOMPARE(false, obj1.resolveSymlinks()); |
|
131 |
obj1.setResolveSymlinks(true); |
|
132 |
QCOMPARE(true, obj1.resolveSymlinks()); |
|
133 |
||
134 |
// bool QDirModel::lazyChildCount() |
|
135 |
// void QDirModel::setLazyChildCount(bool) |
|
136 |
obj1.setLazyChildCount(false); |
|
137 |
QCOMPARE(false, obj1.lazyChildCount()); |
|
138 |
obj1.setLazyChildCount(true); |
|
139 |
QCOMPARE(true, obj1.lazyChildCount()); |
|
140 |
} |
|
141 |
||
142 |
||
143 |
Q_DECLARE_METATYPE(QModelIndex) |
|
144 |
Q_DECLARE_METATYPE(QModelIndexList) |
|
145 |
||
146 |
tst_QDirModel::tst_QDirModel() |
|
147 |
||
148 |
{ |
|
149 |
} |
|
150 |
||
151 |
tst_QDirModel::~tst_QDirModel() |
|
152 |
{ |
|
153 |
} |
|
154 |
||
155 |
void tst_QDirModel::initTestCase() |
|
156 |
{ |
|
157 |
} |
|
158 |
||
159 |
void tst_QDirModel::cleanupTestCase() |
|
160 |
{ |
|
161 |
QDir current; |
|
162 |
current.rmdir(".qtest_hidden"); |
|
163 |
} |
|
164 |
||
165 |
void tst_QDirModel::init() |
|
166 |
{ |
|
167 |
} |
|
168 |
||
169 |
void tst_QDirModel::cleanup() |
|
170 |
{ |
|
171 |
} |
|
172 |
||
173 |
/* |
|
174 |
tests |
|
175 |
*/ |
|
176 |
/* |
|
177 |
void tst_QDirModel::construct() |
|
178 |
{ |
|
179 |
QDirModel model; |
|
180 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
181 |
index = model.index(2, 0, index); |
|
182 |
QVERIFY(index.isValid()); |
|
183 |
QFileInfo info(QDir::currentPath() + "/test/file03.tst"); |
|
184 |
QCOMPARE(model.filePath(index), info.absoluteFilePath()); |
|
185 |
} |
|
186 |
||
187 |
void tst_QDirModel::rowCount() |
|
188 |
{ |
|
189 |
QDirModel model; |
|
190 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
191 |
QVERIFY(index.isValid()); |
|
192 |
QCOMPARE(model.rowCount(index), 4); |
|
193 |
} |
|
194 |
||
195 |
void tst_QDirModel::columnCount() |
|
196 |
{ |
|
197 |
QDirModel model; |
|
198 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
199 |
QVERIFY(index.isValid()); |
|
200 |
QCOMPARE(model.columnCount(index), 4); |
|
201 |
} |
|
202 |
||
203 |
void tst_QDirModel::t_data() |
|
204 |
{ |
|
205 |
QDirModel model; |
|
206 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
207 |
QVERIFY(index.isValid()); |
|
208 |
QCOMPARE(model.rowCount(index), 4); |
|
209 |
||
210 |
index = model.index(2, 0, index); |
|
211 |
QVERIFY(index.isValid()); |
|
212 |
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file03.tst")); |
|
213 |
QCOMPARE(model.rowCount(index), 0); |
|
214 |
} |
|
215 |
||
216 |
void tst_QDirModel::setData() |
|
217 |
{ |
|
218 |
QDirModel model; |
|
219 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
220 |
QVERIFY(index.isValid()); |
|
221 |
||
222 |
index = model.index(2, 0, index); |
|
223 |
QVERIFY(index.isValid()); |
|
224 |
QVERIFY(!model.setData(index, "file0X.tst", Qt::EditRole)); |
|
225 |
} |
|
226 |
||
227 |
void tst_QDirModel::hasChildren() |
|
228 |
{ |
|
229 |
QDirModel model; |
|
230 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
231 |
QVERIFY(index.isValid()); |
|
232 |
||
233 |
index = model.index(2, 0, index); |
|
234 |
QVERIFY(index.isValid()); |
|
235 |
QVERIFY(!model.hasChildren(index)); |
|
236 |
} |
|
237 |
||
238 |
void tst_QDirModel::isEditable() |
|
239 |
{ |
|
240 |
QDirModel model; |
|
241 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
242 |
QVERIFY(index.isValid()); |
|
243 |
||
244 |
index = model.index(2, 0, index); |
|
245 |
QVERIFY(index.isValid()); |
|
246 |
QVERIFY(!(model.flags(index) & Qt::ItemIsEditable)); |
|
247 |
} |
|
248 |
||
249 |
void tst_QDirModel::isDragEnabled() |
|
250 |
{ |
|
251 |
QDirModel model; |
|
252 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
253 |
QVERIFY(index.isValid()); |
|
254 |
||
255 |
index = model.index(2, 0, index); |
|
256 |
QVERIFY(index.isValid()); |
|
257 |
QVERIFY(model.flags(index) & Qt::ItemIsDragEnabled); |
|
258 |
} |
|
259 |
||
260 |
void tst_QDirModel::isDropEnabled() |
|
261 |
{ |
|
262 |
QDirModel model; |
|
263 |
QModelIndex index = model.index(QDir::currentPath() + "/test"); |
|
264 |
QVERIFY(index.isValid()); |
|
265 |
||
266 |
index = model.index(2, 0, index); |
|
267 |
QVERIFY(!(model.flags(index) & Qt::ItemIsDropEnabled)); |
|
268 |
} |
|
269 |
||
270 |
void tst_QDirModel::sort() |
|
271 |
{ |
|
272 |
QDirModel model; |
|
273 |
QModelIndex parent = model.index(QDir::currentPath() + "/test"); |
|
274 |
QVERIFY(parent.isValid()); |
|
275 |
||
276 |
QModelIndex index = model.index(0, 0, parent); |
|
277 |
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst")); |
|
278 |
||
279 |
index = model.index(3, 0, parent); |
|
280 |
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst")); |
|
281 |
||
282 |
model.sort(0, Qt::DescendingOrder); |
|
283 |
parent = model.index(QDir::currentPath() + "/test"); |
|
284 |
||
285 |
index = model.index(0, 0, parent); |
|
286 |
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file04.tst")); |
|
287 |
||
288 |
index = model.index(3, 0, parent); |
|
289 |
QCOMPARE(model.data(index).toString(), QString::fromLatin1("file01.tst")); |
|
290 |
} |
|
291 |
*/ |
|
292 |
||
293 |
void tst_QDirModel::mkdir_data() |
|
294 |
{ |
|
295 |
QTest::addColumn<QString>("dirName"); // the directory to be made under <currentpath>/dirtest |
|
296 |
QTest::addColumn<bool>("mkdirSuccess"); |
|
297 |
QTest::addColumn<int>("rowCount"); |
|
298 |
||
299 |
QTest::newRow("okDirName") << QString("test2") << true << 2; |
|
300 |
QTest::newRow("existingDirName") << QString("test1") << false << 1; |
|
301 |
QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2; |
|
302 |
QTest::newRow("emptyDirName") << QString("") << false << 1; |
|
303 |
QTest::newRow("nullDirName") << QString() << false << 1; |
|
304 |
||
305 |
/* |
|
306 |
QTest::newRow("recursiveDirName") << QString("test2/test3") << false << false; |
|
307 |
QTest::newRow("singleDotDirName") << QString("./test3") << true << true; |
|
308 |
QTest::newRow("outOfTreeDirName") << QString("../test4") << false << false; |
|
309 |
QTest::newRow("insideTreeDirName") << QString("../dirtest/test4") << true << true; |
|
310 |
QTest::newRow("insideTreeDirName2") << QString("./././././../dirtest/./../dirtest/test4") << true << true; |
|
311 |
QTest::newRow("absoluteDirName") << QString(QDir::currentPath() + "/dirtest/test5") << true << true; |
|
312 |
QTest::newRow("outOfTreeDirName") << QString(QDir::currentPath() + "/test5") << false << false; |
|
313 |
||
314 |
// Directory names only illegal on Windows |
|
315 |
#ifdef Q_WS_WIN |
|
316 |
QTest::newRow("illegalDirName") << QString("*") << false << false; |
|
317 |
QTest::newRow("illegalDirName2") << QString("|") << false << false; |
|
318 |
QTest::newRow("onlySpace") << QString(" ") << false << false; |
|
319 |
#endif |
|
320 |
*/ |
|
321 |
} |
|
322 |
||
323 |
void tst_QDirModel::mkdir() |
|
324 |
{ |
|
325 |
QFETCH(QString, dirName); |
|
326 |
QFETCH(bool, mkdirSuccess); |
|
327 |
QFETCH(int, rowCount); |
|
328 |
||
329 |
QDirModel model; |
|
330 |
model.setReadOnly(false); |
|
331 |
||
332 |
QModelIndex parent = model.index(SRCDIR "dirtest"); |
|
333 |
QVERIFY(parent.isValid()); |
|
334 |
QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot |
|
335 |
||
336 |
QModelIndex index = model.mkdir(parent, dirName); |
|
337 |
bool success = index.isValid(); |
|
338 |
int rows = model.rowCount(parent); |
|
339 |
||
340 |
if (success && !model.rmdir(index)) |
|
341 |
QVERIFY(QDir(SRCDIR "dirtests").rmdir(dirName)); |
|
342 |
||
343 |
QCOMPARE(rows, rowCount); |
|
344 |
QCOMPARE(success, mkdirSuccess); |
|
345 |
} |
|
346 |
||
347 |
void tst_QDirModel::rmdir_data() |
|
348 |
{ |
|
349 |
QTest::addColumn<QString>("dirName"); // <currentpath>/dirtest/dirname |
|
350 |
QTest::addColumn<bool>("rmdirSuccess"); |
|
351 |
QTest::addColumn<int>("rowCount"); |
|
352 |
||
353 |
QTest::newRow("okDirName") << QString("test2") << true << 2; |
|
354 |
QTest::newRow("existingDirName") << QString("test1") << false << 1; |
|
355 |
QTest::newRow("nameWithSpace") << QString("ab cd") << true << 2; |
|
356 |
QTest::newRow("emptyDirName") << QString("") << false << 1; |
|
357 |
QTest::newRow("nullDirName") << QString() << false << 1; |
|
358 |
} |
|
359 |
||
360 |
void tst_QDirModel::rmdir() |
|
361 |
{ |
|
362 |
QFETCH(QString, dirName); |
|
363 |
QFETCH(bool, rmdirSuccess); |
|
364 |
QFETCH(int, rowCount); |
|
365 |
||
366 |
QDirModel model; |
|
367 |
model.setReadOnly(false); |
|
368 |
||
369 |
QModelIndex parent = model.index(SRCDIR "/dirtest"); |
|
370 |
QVERIFY(parent.isValid()); |
|
371 |
QCOMPARE(model.rowCount(parent), 1); // start out with only 'test1' - in's in the depot |
|
372 |
||
373 |
QModelIndex index; |
|
374 |
if (rmdirSuccess) { |
|
375 |
index = model.mkdir(parent, dirName); |
|
376 |
QVERIFY(index.isValid()); |
|
377 |
} |
|
378 |
||
379 |
int rows = model.rowCount(parent); |
|
380 |
bool success = model.rmdir(index); |
|
381 |
||
382 |
if (!success) { // cleanup |
|
383 |
QDir dirtests(SRCDIR "/dirtests/"); |
|
384 |
dirtests.rmdir(dirName); |
|
385 |
} |
|
386 |
||
387 |
QCOMPARE(rows, rowCount); |
|
388 |
QCOMPARE(success, rmdirSuccess); |
|
389 |
} |
|
390 |
||
391 |
void tst_QDirModel::rowsAboutToBeRemoved_data() |
|
392 |
{ |
|
393 |
QTest::addColumn<QString>("test_path"); |
|
394 |
QTest::addColumn<QStringList>("initial_files"); |
|
395 |
QTest::addColumn<int>("remove_row"); |
|
396 |
QTest::addColumn<QStringList>("remove_files"); |
|
397 |
QTest::addColumn<QStringList>("expected_files"); |
|
398 |
||
399 |
QString test_path = "test2"; |
|
400 |
QStringList initial_files = (QStringList() |
|
401 |
<< "file1.tst" |
|
402 |
<< "file2.tst" |
|
403 |
<< "file3.tst" |
|
404 |
<< "file4.tst"); |
|
405 |
||
406 |
QTest::newRow("removeFirstRow") |
|
407 |
<< test_path |
|
408 |
<< initial_files |
|
409 |
<< 0 |
|
410 |
<< (QStringList() << "file1.tst") |
|
411 |
<< (QStringList() << "file2.tst" << "file3.tst" << "file4.tst"); |
|
412 |
||
413 |
QTest::newRow("removeMiddle") |
|
414 |
<< test_path |
|
415 |
<< initial_files |
|
416 |
<< 1 |
|
417 |
<< (QStringList() << "file2.tst") |
|
418 |
<< (QStringList() << "file1.tst" << "file3.tst" << "file4.tst"); |
|
419 |
||
420 |
QTest::newRow("removeLastRow") |
|
421 |
<< test_path |
|
422 |
<< initial_files |
|
423 |
<< 3 |
|
424 |
<< (QStringList() << "file4.tst") |
|
425 |
<< (QStringList() << "file1.tst" << "file2.tst" << "file3.tst"); |
|
426 |
||
427 |
} |
|
428 |
||
429 |
bool tst_QDirModel::rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files) |
|
430 |
{ |
|
431 |
QString path = QDir::currentPath() + "/" + test_path; |
|
432 |
if (!QDir::current().mkdir(test_path) && false) { // FIXME |
|
433 |
qDebug() << "failed to create dir" << path; |
|
434 |
return false; |
|
435 |
} |
|
436 |
||
437 |
for (int i = 0; i < initial_files.count(); ++i) { |
|
438 |
QFile file(path + "/" + initial_files.at(i)); |
|
439 |
if (!file.open(QIODevice::WriteOnly)) { |
|
440 |
qDebug() << "failed to open file" << initial_files.at(i); |
|
441 |
return false; |
|
442 |
} |
|
443 |
if (!file.resize(1024)) { |
|
444 |
qDebug() << "failed to resize file" << initial_files.at(i); |
|
445 |
return false; |
|
446 |
} |
|
447 |
if (!file.flush()) { |
|
448 |
qDebug() << "failed to flush file" << initial_files.at(i); |
|
449 |
return false; |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
return true; |
|
454 |
} |
|
455 |
||
456 |
bool tst_QDirModel::rowsAboutToBeRemoved_cleanup(const QString &test_path) |
|
457 |
{ |
|
458 |
QString path = QDir::currentPath() + "/" + test_path; |
|
459 |
QDir dir(path, "*", QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Files); |
|
460 |
QStringList files = dir.entryList(); |
|
461 |
||
462 |
for (int i = 0; i < files.count(); ++i) { |
|
463 |
if (!dir.remove(files.at(i))) { |
|
464 |
qDebug() << "failed to remove file" << files.at(i); |
|
465 |
return false; |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
if (!QDir::current().rmdir(test_path) && false) { // FIXME |
|
470 |
qDebug() << "failed to remove dir" << test_path; |
|
471 |
return false; |
|
472 |
} |
|
473 |
||
474 |
return true; |
|
475 |
} |
|
476 |
||
477 |
void tst_QDirModel::rowsAboutToBeRemoved() |
|
478 |
{ |
|
479 |
QFETCH(QString, test_path); |
|
480 |
QFETCH(QStringList, initial_files); |
|
481 |
QFETCH(int, remove_row); |
|
482 |
QFETCH(QStringList, remove_files); |
|
483 |
QFETCH(QStringList, expected_files); |
|
484 |
||
485 |
rowsAboutToBeRemoved_cleanup(test_path); // clean up first |
|
486 |
QVERIFY(rowsAboutToBeRemoved_init(test_path, initial_files)); |
|
487 |
||
488 |
QDirModel model; |
|
489 |
model.setReadOnly(false); |
|
490 |
||
491 |
qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
492 |
||
493 |
// NOTE: QDirModel will call refresh() when a file is removed. refresh() will reread the entire directory, |
|
494 |
// and emit layoutAboutToBeChanged and layoutChange. So, instead of checking for |
|
495 |
// rowsAboutToBeRemoved/rowsRemoved we check for layoutAboutToBeChanged/layoutChanged |
|
496 |
QSignalSpy spy(&model, SIGNAL(layoutAboutToBeChanged())); |
|
497 |
||
498 |
QModelIndex parent = model.index(test_path); |
|
499 |
QVERIFY(parent.isValid()); |
|
500 |
||
501 |
// remove the file |
|
502 |
{ |
|
503 |
QModelIndex index = model.index(remove_row, 0, parent); |
|
504 |
QVERIFY(index.isValid()); |
|
505 |
QVERIFY(model.remove(index)); |
|
506 |
} |
|
507 |
||
508 |
QCOMPARE(spy.count(), 1); |
|
509 |
||
510 |
// Compare the result |
|
511 |
for (int row = 0; row < expected_files.count(); ++row) { |
|
512 |
QModelIndex index = model.index(row, 0, parent); |
|
513 |
QString str = index.data().toString(); |
|
514 |
QCOMPARE(str, expected_files.at(row)); |
|
515 |
} |
|
516 |
||
517 |
QVERIFY(rowsAboutToBeRemoved_cleanup(test_path)); |
|
518 |
} |
|
519 |
||
520 |
void tst_QDirModel::hidden() |
|
521 |
{ |
|
522 |
#ifdef Q_OS_UNIX |
|
523 |
QDir current; |
|
524 |
current.mkdir(".qtest_hidden"); |
|
525 |
||
526 |
QDirModel model; |
|
527 |
QModelIndex index = model.index(QDir::currentPath() + "/.qtest_hidden"); |
|
528 |
//QVERIFY(!index.isValid()); // hidden items are not listed, but if you specify a valid path, it will give a valid index |
|
529 |
||
530 |
current.mkdir(".qtest_hidden/qtest_visible"); |
|
531 |
QModelIndex index2 = model.index(QDir::currentPath() + "/.qtest_hidden/qtest_visible"); |
|
532 |
QVERIFY(index2.isValid()); |
|
533 |
||
534 |
QDirModel model2; |
|
535 |
model2.setFilter(model2.filter() | QDir::Hidden); |
|
536 |
index = model2.index(QDir::currentPath() + "/.qtest_hidden"); |
|
537 |
QVERIFY(index.isValid()); |
|
538 |
#else |
|
539 |
QSKIP("Test not implemented on non-Unixes", SkipAll); |
|
540 |
#endif |
|
541 |
} |
|
542 |
||
543 |
void tst_QDirModel::fileName_data() |
|
544 |
{ |
|
545 |
QTest::addColumn<QString>("path"); |
|
546 |
QTest::addColumn<QString>("result"); |
|
547 |
||
548 |
QTest::newRow("invalid") << "" << ""; |
|
549 |
//QTest::newRow("root") << "/" << "/"; |
|
550 |
//QTest::newRow("home") << "/home" << "home"; |
|
551 |
// TODO add symlink test too |
|
552 |
} |
|
553 |
||
554 |
void tst_QDirModel::fileName() |
|
555 |
{ |
|
556 |
QDirModel model; |
|
557 |
||
558 |
QFETCH(QString, path); |
|
559 |
QFETCH(QString, result); |
|
560 |
QCOMPARE(model.fileName(model.index(path)), result); |
|
561 |
} |
|
562 |
||
563 |
#if 0 |
|
564 |
void tst_QDirModel::unreadable() |
|
565 |
{ |
|
566 |
#ifdef Q_OS_UNIX |
|
567 |
//QFile current("qtest_unreadable"); |
|
568 |
//QVERIFY(current.setPermissions(QFile::WriteOwner)); |
|
569 |
||
570 |
QDirModel model; |
|
571 |
QModelIndex index = model.index(QDir::currentPath() + "/qtest_unreadable"); |
|
572 |
QVERIFY(!index.isValid()); |
|
573 |
||
574 |
QDirModel model2; |
|
575 |
model2.setFilter(model2.filter() | QDir::Hidden); |
|
576 |
index = model2.index(QDir::currentPath() + "/qtest_unreadable"); |
|
577 |
QVERIFY(index.isValid()); |
|
578 |
#else |
|
579 |
QSKIP("Test not implemented on non-Unixes", SkipAll); |
|
580 |
#endif |
|
581 |
} |
|
582 |
#endif |
|
583 |
||
584 |
void tst_QDirModel::filePath() |
|
585 |
{ |
|
586 |
QFile::remove(SRCDIR "test.lnk"); |
|
587 |
QVERIFY(QFile(SRCDIR "tst_qdirmodel.cpp").link(SRCDIR "test.lnk")); |
|
588 |
QDirModel model; |
|
589 |
model.setResolveSymlinks(false); |
|
590 |
QModelIndex index = model.index(SRCDIR "test.lnk"); |
|
591 |
QVERIFY(index.isValid()); |
|
592 |
#if defined(Q_OS_SYMBIAN) |
|
593 |
// Since model will force lowercase path in Symbian, make case insensitive compare |
|
594 |
// Note: Windows should fail this, too, if test path has any uppercase letters. |
|
595 |
QCOMPARE(model.filePath(index).toLower(), QString(SRCDIR).toLower() + "test.lnk"); |
|
596 |
model.setResolveSymlinks(true); |
|
597 |
QCOMPARE(model.filePath(index).toLower(), QString(SRCDIR).toLower() + "tst_qdirmodel.cpp"); |
|
598 |
#else |
|
599 |
#ifndef Q_OS_WINCE |
|
600 |
QString path = SRCDIR; |
|
601 |
#else |
|
602 |
QString path = QFileInfo(SRCDIR).absoluteFilePath() + "/"; |
|
603 |
#endif |
|
604 |
QCOMPARE(model.filePath(index), path + QString( "test.lnk")); |
|
605 |
model.setResolveSymlinks(true); |
|
606 |
QCOMPARE(model.filePath(index), path + QString( "tst_qdirmodel.cpp")); |
|
607 |
#endif |
|
608 |
QFile::remove(SRCDIR "test.lnk"); |
|
609 |
} |
|
610 |
||
611 |
void tst_QDirModel::task196768_sorting() |
|
612 |
{ |
|
613 |
//this task showed that the persistent model indexes got corrupted when sorting |
|
614 |
QString path = SRCDIR; |
|
615 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
616 |
#ifdef Q_OS_SYMBIAN |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
617 |
if(!RProcess().HasCapability(ECapabilityAllFiles)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
618 |
QEXPECT_FAIL("", "QTBUG-9746", Continue); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
619 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
620 |
|
0 | 621 |
QDirModel model; |
622 |
||
623 |
/* QDirModel has a bug if we show the content of the subdirectory inside a hidden directory |
|
624 |
and we don't add QDir::Hidden. But as QDirModel is deprecated, we decided not to fix it. */ |
|
625 |
model.setFilter(QDir::AllEntries | QDir::Hidden | QDir::AllDirs); |
|
626 |
||
627 |
QTreeView view; |
|
628 |
QPersistentModelIndex index = model.index(path); |
|
629 |
view.setModel(&model); |
|
630 |
QModelIndex index2 = model.index(path); |
|
631 |
QCOMPARE(index.data(), index2.data()); |
|
632 |
view.setRootIndex(index); |
|
633 |
index2 = model.index(path); |
|
634 |
QCOMPARE(index.data(), index2.data()); |
|
635 |
view.setCurrentIndex(index); |
|
636 |
index2 = model.index(path); |
|
637 |
QCOMPARE(index.data(), index2.data()); |
|
638 |
view.setSortingEnabled(true); |
|
639 |
index2 = model.index(path); |
|
640 |
QCOMPARE(index.data(), index2.data()); |
|
641 |
} |
|
642 |
||
643 |
void tst_QDirModel::filter() |
|
644 |
{ |
|
645 |
QDirModel model; |
|
646 |
model.setNameFilters(QStringList() << "*.nada"); |
|
647 |
QModelIndex index = model.index(SRCDIR "test"); |
|
648 |
Q_ASSERT(model.rowCount(index) == 0); |
|
649 |
QModelIndex index2 = model.index(SRCDIR "test/file01.tst"); |
|
650 |
Q_ASSERT(!index2.isValid()); |
|
651 |
Q_ASSERT(model.rowCount(index) == 0); |
|
652 |
} |
|
653 |
||
654 |
void tst_QDirModel::task244669_remove() |
|
655 |
{ |
|
656 |
QFile f1(SRCDIR "dirtest/f1.txt"); |
|
657 |
QVERIFY(f1.open(QIODevice::WriteOnly)); |
|
658 |
f1.close(); |
|
659 |
QFile f2(SRCDIR "dirtest/f2.txt"); |
|
660 |
QVERIFY(f2.open(QIODevice::WriteOnly)); |
|
661 |
f2.close(); |
|
662 |
||
663 |
QDirModel model; |
|
664 |
model.setReadOnly(false); |
|
665 |
QPersistentModelIndex parent = model.index(SRCDIR "dirtest"); |
|
666 |
QPersistentModelIndex index2 = model.index(SRCDIR "dirtest/f2.txt"); |
|
667 |
QPersistentModelIndex index1 = model.index(SRCDIR "dirtest/f1.txt"); |
|
668 |
||
669 |
QVERIFY(parent.isValid()); |
|
670 |
QVERIFY(index1.isValid()); |
|
671 |
QVERIFY(index2.isValid()); |
|
672 |
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); |
|
673 |
QCOMPARE(index1.data() , model.index(SRCDIR "dirtest/f1.txt").data()); |
|
674 |
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data()); |
|
675 |
||
676 |
QVERIFY(model.remove(index1)); |
|
677 |
||
678 |
QVERIFY(parent.isValid()); |
|
679 |
QVERIFY(!index1.isValid()); |
|
680 |
QVERIFY(index2.isValid()); |
|
681 |
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); |
|
682 |
QCOMPARE(index2.data() , model.index(SRCDIR "dirtest/f2.txt").data()); |
|
683 |
||
684 |
QVERIFY(model.remove(index2)); |
|
685 |
||
686 |
QVERIFY(parent.isValid()); |
|
687 |
QVERIFY(!index2.isValid()); |
|
688 |
QVERIFY(!index1.isValid()); |
|
689 |
QCOMPARE(parent.data() , model.index(SRCDIR "dirtest").data()); |
|
690 |
} |
|
691 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
692 |
void tst_QDirModel::roleNames_data() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
693 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
694 |
QTest::addColumn<int>("role"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
695 |
QTest::addColumn<QByteArray>("roleName"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
696 |
QTest::newRow("decoration") << int(Qt::DecorationRole) << QByteArray("decoration"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
697 |
QTest::newRow("display") << int(Qt::DisplayRole) << QByteArray("display"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
698 |
QTest::newRow("fileIcon") << int(QDirModel::FileIconRole) << QByteArray("fileIcon"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
699 |
QTest::newRow("filePath") << int(QDirModel::FilePathRole) << QByteArray("filePath"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
700 |
QTest::newRow("fileName") << int(QDirModel::FileNameRole) << QByteArray("fileName"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
701 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
702 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
703 |
void tst_QDirModel::roleNames() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
704 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
705 |
QDirModel model; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
706 |
QHash<int, QByteArray> roles = model.roleNames(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
707 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
708 |
QFETCH(int, role); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
709 |
QVERIFY(roles.contains(role)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
710 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
711 |
QFETCH(QByteArray, roleName); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
712 |
QList<QByteArray> values = roles.values(role); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
713 |
QVERIFY(values.contains(roleName)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
714 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
715 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
716 |
|
0 | 717 |
QTEST_MAIN(tst_QDirModel) |
718 |
#include "tst_qdirmodel.moc" |