author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
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:
3
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 |
||
45 |
||
46 |
#include <qfile.h> |
|
47 |
#include <qdir.h> |
|
48 |
#include <qcoreapplication.h> |
|
49 |
#include <qtemporaryfile.h> |
|
50 |
#include <qdir.h> |
|
51 |
#include <qfileinfo.h> |
|
52 |
#ifdef Q_OS_UNIX |
|
53 |
#include <fcntl.h> |
|
54 |
#include <unistd.h> |
|
55 |
#include <sys/stat.h> |
|
56 |
#endif |
|
57 |
#ifdef Q_OS_WIN |
|
58 |
#include <qt_windows.h> |
|
59 |
#endif |
|
60 |
#include <qplatformdefs.h> |
|
61 |
#include <qdebug.h> |
|
62 |
#ifdef Q_OS_SYMBIAN |
|
63 |
#include <f32file.h> |
|
64 |
#include <private/qcore_symbian_p.h> |
|
65 |
#endif |
|
66 |
#include "../network-settings.h" |
|
67 |
#include <private/qfileinfo_p.h> |
|
68 |
||
69 |
#if defined(Q_OS_SYMBIAN) |
|
70 |
# define SRCDIR "" |
|
71 |
#endif |
|
72 |
||
73 |
//TESTED_CLASS= |
|
74 |
//TESTED_FILES= |
|
75 |
||
76 |
class tst_QFileInfo : public QObject |
|
77 |
{ |
|
78 |
Q_OBJECT |
|
79 |
||
80 |
public: |
|
81 |
tst_QFileInfo(); |
|
82 |
~tst_QFileInfo(); |
|
83 |
||
84 |
private slots: |
|
85 |
void getSetCheck(); |
|
86 |
||
87 |
void copy(); |
|
88 |
||
89 |
void isFile_data(); |
|
90 |
void isFile(); |
|
91 |
||
92 |
void isDir_data(); |
|
93 |
void isDir(); |
|
94 |
||
95 |
void isRoot_data(); |
|
96 |
void isRoot(); |
|
97 |
||
98 |
void exists_data(); |
|
99 |
void exists(); |
|
100 |
||
101 |
void absolutePath_data(); |
|
102 |
void absolutePath(); |
|
103 |
||
104 |
void absFilePath_data(); |
|
105 |
void absFilePath(); |
|
106 |
||
107 |
void canonicalPath(); |
|
108 |
void canonicalFilePath(); |
|
109 |
||
110 |
void fileName_data(); |
|
111 |
void fileName(); |
|
112 |
||
113 |
void bundleName_data(); |
|
114 |
void bundleName(); |
|
115 |
||
116 |
void dir_data(); |
|
117 |
void dir(); |
|
118 |
||
119 |
void suffix_data(); |
|
120 |
void suffix(); |
|
121 |
||
122 |
void completeSuffix_data(); |
|
123 |
void completeSuffix(); |
|
124 |
||
125 |
void baseName_data(); |
|
126 |
void baseName(); |
|
127 |
||
128 |
void completeBaseName_data(); |
|
129 |
void completeBaseName(); |
|
130 |
||
131 |
void permission_data(); |
|
132 |
void permission(); |
|
133 |
||
134 |
void size_data(); |
|
135 |
void size(); |
|
136 |
||
137 |
void systemFiles(); |
|
138 |
||
139 |
void compare_data(); |
|
140 |
void compare(); |
|
141 |
||
142 |
void consistent_data(); |
|
143 |
void consistent(); |
|
144 |
||
145 |
void fileTimes_data(); |
|
146 |
void fileTimes(); |
|
147 |
void fileTimes_oldFile(); |
|
148 |
||
149 |
void isSymLink_data(); |
|
150 |
void isSymLink(); |
|
151 |
||
152 |
void isHidden_data(); |
|
153 |
void isHidden(); |
|
154 |
||
155 |
void isBundle_data(); |
|
156 |
void isBundle(); |
|
157 |
||
158 |
void isLocalFs_data(); |
|
159 |
void isLocalFs(); |
|
160 |
||
161 |
void refresh(); |
|
162 |
||
163 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
164 |
void brokenShortcut(); |
|
165 |
#endif |
|
166 |
||
167 |
void isWritable(); |
|
168 |
void isExecutable(); |
|
169 |
void testDecomposedUnicodeNames_data(); |
|
170 |
void testDecomposedUnicodeNames(); |
|
171 |
||
172 |
void equalOperator() const; |
|
173 |
void equalOperatorWithDifferentSlashes() const; |
|
174 |
void notEqualOperator() const; |
|
175 |
}; |
|
176 |
||
177 |
tst_QFileInfo::tst_QFileInfo() |
|
178 |
{ |
|
179 |
} |
|
180 |
||
181 |
tst_QFileInfo::~tst_QFileInfo() |
|
182 |
{ |
|
183 |
QFile::remove("brokenlink.lnk"); |
|
184 |
QFile::remove("link.lnk"); |
|
185 |
QFile::remove("file1"); |
|
186 |
QFile::remove("dummyfile"); |
|
187 |
#ifdef Q_OS_SYMBIAN |
|
188 |
QFile::remove("hidden.txt"); |
|
189 |
QFile::remove("nothidden.txt"); |
|
190 |
#else |
|
191 |
QFile::remove("tempfile.txt"); |
|
192 |
#endif |
|
193 |
||
194 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) |
|
195 |
QDir().rmdir("./.hidden-directory"); |
|
196 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
197 |
#ifdef Q_OS_WIN |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
198 |
QDir().rmdir("./hidden-directory"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
199 |
#endif |
0 | 200 |
} |
201 |
||
202 |
// Testing get/set functions |
|
203 |
void tst_QFileInfo::getSetCheck() |
|
204 |
{ |
|
205 |
QFileInfo obj1; |
|
206 |
// bool QFileInfo::caching() |
|
207 |
// void QFileInfo::setCaching(bool) |
|
208 |
obj1.setCaching(false); |
|
209 |
QCOMPARE(false, obj1.caching()); |
|
210 |
obj1.setCaching(true); |
|
211 |
QCOMPARE(true, obj1.caching()); |
|
212 |
} |
|
213 |
||
214 |
static QFileInfoPrivate* getPrivate(QFileInfo &info) |
|
215 |
{ |
|
216 |
return (*reinterpret_cast<QFileInfoPrivate**>(&info)); |
|
217 |
} |
|
218 |
||
219 |
void tst_QFileInfo::copy() |
|
220 |
{ |
|
221 |
QTemporaryFile *t; |
|
222 |
t = new QTemporaryFile; |
|
223 |
t->open(); |
|
224 |
QFileInfo info(t->fileName()); |
|
225 |
QVERIFY(info.exists()); |
|
226 |
||
227 |
//copy constructor |
|
228 |
QFileInfo info2(info); |
|
229 |
QFileInfoPrivate *privateInfo = getPrivate(info); |
|
230 |
QFileInfoPrivate *privateInfo2 = getPrivate(info2); |
|
231 |
QCOMPARE(privateInfo->data, privateInfo2->data); |
|
232 |
||
233 |
//operator = |
|
234 |
QFileInfo info3 = info; |
|
235 |
QFileInfoPrivate *privateInfo3 = getPrivate(info3); |
|
236 |
QCOMPARE(privateInfo->data, privateInfo3->data); |
|
237 |
QCOMPARE(privateInfo2->data, privateInfo3->data); |
|
238 |
||
239 |
//refreshing info3 will detach it |
|
240 |
QFile file(info.absoluteFilePath()); |
|
241 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
242 |
QCOMPARE(file.write("JAJAJAA"), qint64(7)); |
|
243 |
file.flush(); |
|
244 |
||
245 |
QTest::qWait(250); |
|
246 |
#if defined(Q_OS_WIN) || defined(Q_OS_WINCE) |
|
247 |
if (QSysInfo::windowsVersion() & QSysInfo::WV_VISTA || |
|
248 |
QSysInfo::windowsVersion() & QSysInfo::WV_CE_based) |
|
249 |
file.close(); |
|
250 |
#endif |
|
251 |
#if defined(Q_OS_WINCE) |
|
252 |
// On Windows CE we need to close the file. |
|
253 |
// Otherwise the content will be cached and not |
|
254 |
// flushed to the storage, although we flushed it |
|
255 |
// manually!!! CE has interim cache, we cannot influence. |
|
256 |
QTest::qWait(5000); |
|
257 |
#endif |
|
258 |
info3.refresh(); |
|
259 |
QVERIFY(privateInfo->data != privateInfo3->data); |
|
260 |
QVERIFY(privateInfo2->data != privateInfo3->data); |
|
261 |
QCOMPARE(privateInfo->data, privateInfo2->data); |
|
262 |
} |
|
263 |
||
264 |
void tst_QFileInfo::isFile_data() |
|
265 |
{ |
|
266 |
QTest::addColumn<QString>("path"); |
|
267 |
QTest::addColumn<bool>("expected"); |
|
268 |
||
269 |
QTest::newRow("data0") << QDir::currentPath() << false; |
|
270 |
QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << true; |
|
271 |
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false; |
|
272 |
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true; |
|
273 |
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; |
|
274 |
} |
|
275 |
||
276 |
void tst_QFileInfo::isFile() |
|
277 |
{ |
|
278 |
QFETCH(QString, path); |
|
279 |
QFETCH(bool, expected); |
|
280 |
||
281 |
QFileInfo fi(path); |
|
282 |
QCOMPARE(fi.isFile(), expected); |
|
283 |
} |
|
284 |
||
285 |
||
286 |
void tst_QFileInfo::isDir_data() |
|
287 |
{ |
|
288 |
// create a broken symlink |
|
289 |
QFile::remove("brokenlink.lnk"); |
|
290 |
QFile::remove("dummyfile"); |
|
291 |
QFile file3("dummyfile"); |
|
292 |
file3.open(QIODevice::WriteOnly); |
|
293 |
if (file3.link("brokenlink.lnk")) { |
|
294 |
file3.remove(); |
|
295 |
QFileInfo info3("brokenlink.lnk"); |
|
296 |
QVERIFY( info3.isSymLink() ); |
|
297 |
} |
|
298 |
||
299 |
QTest::addColumn<QString>("path"); |
|
300 |
QTest::addColumn<bool>("expected"); |
|
301 |
||
302 |
QTest::newRow("data0") << QDir::currentPath() << true; |
|
303 |
QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << false; |
|
304 |
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << true; |
|
305 |
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << false; |
|
306 |
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; |
|
307 |
||
308 |
QTest::newRow("simple dir") << SRCDIR "resources" << true; |
|
309 |
QTest::newRow("simple dir with slash") << SRCDIR "resources/" << true; |
|
310 |
||
311 |
QTest::newRow("broken link") << "brokenlink.lnk" << false; |
|
312 |
||
313 |
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) |
|
314 |
QTest::newRow("drive 1") << "c:" << true; |
|
315 |
QTest::newRow("drive 2") << "c:/" << true; |
|
316 |
//QTest::newRow("drive 2") << "t:s" << false; |
|
317 |
#endif |
|
318 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
319 |
QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; |
|
320 |
QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; |
|
321 |
QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true; |
|
322 |
QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true; |
|
323 |
QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true; |
|
324 |
QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true; |
|
325 |
QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false; |
|
326 |
#endif |
|
327 |
} |
|
328 |
||
329 |
void tst_QFileInfo::isDir() |
|
330 |
{ |
|
331 |
QFETCH(QString, path); |
|
332 |
QFETCH(bool, expected); |
|
333 |
||
334 |
QFileInfo fi(path); |
|
335 |
QCOMPARE(fi.isDir(), expected); |
|
336 |
} |
|
337 |
||
338 |
void tst_QFileInfo::isRoot_data() |
|
339 |
{ |
|
340 |
QTest::addColumn<QString>("path"); |
|
341 |
QTest::addColumn<bool>("expected"); |
|
342 |
QTest::newRow("data0") << QDir::currentPath() << false; |
|
343 |
QTest::newRow("data1") << "/" << true; |
|
344 |
QTest::newRow("data2") << "*" << false; |
|
345 |
QTest::newRow("data3") << "/*" << false; |
|
346 |
QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false; |
|
347 |
QTest::newRow("data5") << ":/" << true; |
|
348 |
||
349 |
QTest::newRow("simple dir") << SRCDIR "resources" << false; |
|
350 |
QTest::newRow("simple dir with slash") << SRCDIR "resources/" << false; |
|
351 |
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) |
|
352 |
QTest::newRow("drive 1") << "c:" << false; |
|
353 |
QTest::newRow("drive 2") << "c:/" << true; |
|
354 |
QTest::newRow("drive 3") << "p:/" << false; |
|
355 |
#endif |
|
356 |
||
357 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
358 |
QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; |
|
359 |
QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; |
|
360 |
QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << false; |
|
361 |
QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << false; |
|
362 |
QTest::newRow("unc 7") << "//ahostthatshouldnotexist" << false; |
|
363 |
#endif |
|
364 |
} |
|
365 |
||
366 |
void tst_QFileInfo::isRoot() |
|
367 |
{ |
|
368 |
QFETCH(QString, path); |
|
369 |
QFETCH(bool, expected); |
|
370 |
||
371 |
QFileInfo fi(path); |
|
372 |
QCOMPARE(fi.isRoot(), expected); |
|
373 |
} |
|
374 |
||
375 |
void tst_QFileInfo::exists_data() |
|
376 |
{ |
|
377 |
QTest::addColumn<QString>("path"); |
|
378 |
QTest::addColumn<bool>("expected"); |
|
379 |
||
380 |
QTest::newRow("data0") << QDir::currentPath() << true; |
|
381 |
QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << true; |
|
382 |
QTest::newRow("data2") << "/I/do_not_expect_this_path_to_exist/" << false; |
|
383 |
QTest::newRow("data3") << ":/tst_qfileinfo/resources/" << true; |
|
384 |
QTest::newRow("data4") << ":/tst_qfileinfo/resources/file1" << true; |
|
385 |
QTest::newRow("data5") << ":/I/do_not_expect_this_path_to_exist/" << false; |
|
386 |
QTest::newRow("data6") << SRCDIR "resources/*" << false; |
|
387 |
QTest::newRow("data7") << SRCDIR "resources/*.foo" << false; |
|
388 |
QTest::newRow("data8") << SRCDIR "resources/*.ext1" << false; |
|
389 |
QTest::newRow("data9") << SRCDIR "resources/file?.ext1" << false; |
|
390 |
QTest::newRow("data10") << "." << true; |
|
391 |
QTest::newRow("data11") << ". " << false; |
|
392 |
||
393 |
QTest::newRow("simple dir") << SRCDIR "resources" << true; |
|
394 |
QTest::newRow("simple dir with slash") << SRCDIR "resources/" << true; |
|
395 |
||
396 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
397 |
QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; |
|
398 |
QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true; |
|
399 |
QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true; |
|
400 |
QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true; |
|
401 |
QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true; |
|
402 |
QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true; |
|
403 |
QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false; |
|
404 |
QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false; |
|
405 |
QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; |
|
406 |
#endif |
|
407 |
} |
|
408 |
||
409 |
void tst_QFileInfo::exists() |
|
410 |
{ |
|
411 |
QFETCH(QString, path); |
|
412 |
QFETCH(bool, expected); |
|
413 |
||
414 |
QFileInfo fi(path); |
|
415 |
QCOMPARE(fi.exists(), expected); |
|
416 |
} |
|
417 |
||
418 |
void tst_QFileInfo::absolutePath_data() |
|
419 |
{ |
|
420 |
QTest::addColumn<QString>("file"); |
|
421 |
QTest::addColumn<QString>("path"); |
|
422 |
QTest::addColumn<QString>("filename"); |
|
423 |
||
424 |
QString drivePrefix; |
|
425 |
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) |
|
426 |
drivePrefix = QDir::currentPath().left(2); |
|
427 |
QString nonCurrentDrivePrefix = |
|
428 |
drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:"); |
|
429 |
||
430 |
// Make sure drive-relative paths return correct absolute paths (task 255326) |
|
431 |
QTest::newRow("<current drive>:my.dll") << drivePrefix + "my.dll" << QDir::currentPath() << "my.dll"; |
|
432 |
QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "my.dll" |
|
433 |
<< nonCurrentDrivePrefix + "/" |
|
434 |
<< "my.dll"; |
|
435 |
#endif |
|
436 |
QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << ""; |
|
437 |
QTest::newRow("1") << "/machine/share/dir1" << drivePrefix + "/machine/share" << "dir1"; |
|
438 |
QTest::newRow("2") << "/usr/local/bin" << drivePrefix + "/usr/local" << "bin"; |
|
439 |
QTest::newRow("3") << "/usr/local/bin/" << drivePrefix + "/usr/local/bin" << ""; |
|
440 |
QTest::newRow("/test") << "/test" << drivePrefix + "/" << "test"; |
|
441 |
||
442 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
443 |
// see task 102898 |
|
444 |
QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/" |
|
445 |
<< "autoexec.bat"; |
|
446 |
#endif |
|
447 |
} |
|
448 |
||
449 |
void tst_QFileInfo::absolutePath() |
|
450 |
{ |
|
451 |
QFETCH(QString, file); |
|
452 |
QFETCH(QString, path); |
|
453 |
QFETCH(QString, filename); |
|
454 |
||
455 |
QFileInfo fi(file); |
|
456 |
||
457 |
QCOMPARE(fi.absolutePath(), path); |
|
458 |
QCOMPARE(fi.fileName(), filename); |
|
459 |
} |
|
460 |
||
461 |
void tst_QFileInfo::absFilePath_data() |
|
462 |
{ |
|
463 |
QTest::addColumn<QString>("file"); |
|
464 |
QTest::addColumn<QString>("expected"); |
|
465 |
||
466 |
QTest::newRow("relativeFile") << "tmp.txt" << QDir::currentPath() + "/tmp.txt"; |
|
467 |
QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << QDir::currentPath() + "/" + "temp/tmp.txt"; |
|
468 |
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) |
|
469 |
QString curr = QDir::currentPath(); |
|
470 |
||
471 |
curr.remove(0, 2); // Make it a absolute path with no drive specifier: \depot\qt-4.2\tests\auto\qfileinfo |
|
472 |
QTest::newRow(".") << curr << QDir::currentPath(); |
|
473 |
QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "C:/home/andy/tmp.txt"; |
|
474 |
||
475 |
// Make sure drive-relative paths return correct absolute paths (task 255326) |
|
476 |
QString drivePrefix = QDir::currentPath().left(2); |
|
477 |
QString nonCurrentDrivePrefix = |
|
478 |
drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:"); |
|
479 |
||
480 |
QTest::newRow("<current drive>:my.dll") << drivePrefix + "temp/my.dll" << QDir::currentPath() + "/temp/my.dll"; |
|
481 |
QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "temp/my.dll" |
|
482 |
<< nonCurrentDrivePrefix + "/temp/my.dll"; |
|
483 |
#else |
|
484 |
QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "/home/andy/tmp.txt"; |
|
485 |
#endif |
|
486 |
} |
|
487 |
||
488 |
void tst_QFileInfo::absFilePath() |
|
489 |
{ |
|
490 |
QFETCH(QString, file); |
|
491 |
QFETCH(QString, expected); |
|
492 |
||
493 |
QFileInfo fi(file); |
|
494 |
QCOMPARE(fi.absoluteFilePath(), expected); |
|
495 |
} |
|
496 |
||
497 |
void tst_QFileInfo::canonicalPath() |
|
498 |
{ |
|
499 |
QTemporaryFile tempFile; |
|
500 |
tempFile.setAutoRemove(true); |
|
501 |
tempFile.open(); |
|
502 |
QFileInfo fi(tempFile.fileName()); |
|
503 |
QCOMPARE(fi.canonicalPath(), QFileInfo(QDir::tempPath()).canonicalFilePath()); |
|
504 |
} |
|
505 |
||
506 |
void tst_QFileInfo::canonicalFilePath() |
|
507 |
{ |
|
508 |
const QString fileName("tmp.canon"); |
|
509 |
QFile tempFile(fileName); |
|
510 |
QVERIFY(tempFile.open(QFile::WriteOnly)); |
|
511 |
QFileInfo fi(tempFile.fileName()); |
|
512 |
QCOMPARE(fi.canonicalFilePath(), QDir::currentPath() + "/" + fileName); |
|
513 |
tempFile.remove(); |
|
514 |
||
515 |
// This used to crash on Mac, verify that it doesn't anymore. |
|
516 |
QFileInfo info("/tmp/../../../../../../../../../../../../../../../../../"); |
|
517 |
info.canonicalFilePath(); |
|
518 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
// This used to crash on Mac |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
QFileInfo dontCrash(QLatin1String("/")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
QCOMPARE(dontCrash.canonicalFilePath(), QLatin1String("/")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
524 |
|
0 | 525 |
#ifndef Q_OS_WIN |
526 |
// test symlinks |
|
527 |
QFile::remove("link.lnk"); |
|
528 |
{ |
|
529 |
QFile file(SRCDIR "tst_qfileinfo.cpp"); |
|
530 |
if (file.link("link.lnk")) { |
|
531 |
QFileInfo info1(file); |
|
532 |
QFileInfo info2("link.lnk"); |
|
533 |
QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); |
|
534 |
} |
|
535 |
} |
|
536 |
# if !defined(Q_OS_SYMBIAN) |
|
537 |
// Symbian doesn't support links to directories |
|
538 |
{ |
|
539 |
const QString link(QDir::tempPath() + QDir::separator() + "tst_qfileinfo"); |
|
540 |
QFile::remove(link); |
|
541 |
QFile file(QDir::currentPath()); |
|
542 |
if (file.link(link)) { |
|
543 |
QFile tempfile("tempfile.txt"); |
|
544 |
tempfile.open(QIODevice::ReadWrite); |
|
545 |
tempfile.write("This file is generated by the QFileInfo autotest."); |
|
546 |
QVERIFY(tempfile.flush()); |
|
547 |
tempfile.close(); |
|
548 |
||
549 |
QFileInfo info1("tempfile.txt"); |
|
550 |
QFileInfo info2(link + QDir::separator() + "tempfile.txt"); |
|
551 |
||
552 |
QVERIFY(info1.exists()); |
|
553 |
QVERIFY(info2.exists()); |
|
554 |
QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); |
|
555 |
||
556 |
QFileInfo info3(link + QDir::separator() + "link.lnk"); |
|
557 |
QFileInfo info4(SRCDIR "tst_qfileinfo.cpp"); |
|
558 |
QVERIFY(!info3.canonicalFilePath().isEmpty()); |
|
559 |
QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath()); |
|
560 |
||
561 |
tempfile.remove(); |
|
562 |
} |
|
563 |
} |
|
564 |
{ |
|
565 |
QString link(QDir::tempPath() + QDir::separator() + "tst_qfileinfo" |
|
566 |
+ QDir::separator() + "link_to_tst_qfileinfo"); |
|
567 |
QFile::remove(link); |
|
568 |
||
569 |
QFile file(QDir::tempPath() + QDir::separator() + "tst_qfileinfo" |
|
570 |
+ QDir::separator() + "tst_qfileinfo.cpp"); |
|
571 |
if (file.link(link)) |
|
572 |
{ |
|
573 |
QFileInfo info1("tst_qfileinfo.cpp"); |
|
574 |
QFileInfo info2(link); |
|
575 |
QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); |
|
576 |
} |
|
577 |
} |
|
578 |
# endif |
|
579 |
#endif |
|
580 |
} |
|
581 |
||
582 |
void tst_QFileInfo::fileName_data() |
|
583 |
{ |
|
584 |
QTest::addColumn<QString>("file"); |
|
585 |
QTest::addColumn<QString>("expected"); |
|
586 |
||
587 |
QTest::newRow("relativeFile") << "tmp.txt" << "tmp.txt"; |
|
588 |
QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << "tmp.txt"; |
|
589 |
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) |
|
590 |
QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "tmp.txt"; |
|
591 |
#else |
|
592 |
QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "tmp.txt"; |
|
593 |
#endif |
|
594 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1.ext1"; |
|
595 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1.ext1.ext2"; |
|
596 |
||
597 |
QTest::newRow("ending slash [small]") << QString::fromLatin1("/a/") << QString::fromLatin1(""); |
|
598 |
QTest::newRow("no ending slash [small]") << QString::fromLatin1("/a") << QString::fromLatin1("a"); |
|
599 |
||
600 |
QTest::newRow("ending slash") << QString::fromLatin1("/somedir/") << QString::fromLatin1(""); |
|
601 |
QTest::newRow("no ending slash") << QString::fromLatin1("/somedir") << QString::fromLatin1("somedir"); |
|
602 |
} |
|
603 |
||
604 |
void tst_QFileInfo::fileName() |
|
605 |
{ |
|
606 |
QFETCH(QString, file); |
|
607 |
QFETCH(QString, expected); |
|
608 |
||
609 |
QFileInfo fi(file); |
|
610 |
QCOMPARE(fi.fileName(), expected); |
|
611 |
} |
|
612 |
||
613 |
void tst_QFileInfo::bundleName_data() |
|
614 |
{ |
|
615 |
QTest::addColumn<QString>("file"); |
|
616 |
QTest::addColumn<QString>("expected"); |
|
617 |
||
618 |
QTest::newRow("root") << "/" << ""; |
|
619 |
QTest::newRow("etc") << "/etc" << ""; |
|
620 |
#ifdef Q_OS_MAC |
|
621 |
QTest::newRow("safari") << "/Applications/Safari.app" << "Safari"; |
|
622 |
#endif |
|
623 |
} |
|
624 |
||
625 |
void tst_QFileInfo::bundleName() |
|
626 |
{ |
|
627 |
QFETCH(QString, file); |
|
628 |
QFETCH(QString, expected); |
|
629 |
||
630 |
QFileInfo fi(file); |
|
631 |
QCOMPARE(fi.bundleName(), expected); |
|
632 |
} |
|
633 |
||
634 |
void tst_QFileInfo::dir_data() |
|
635 |
{ |
|
636 |
QTest::addColumn<QString>("file"); |
|
637 |
QTest::addColumn<bool>("absPath"); |
|
638 |
QTest::addColumn<QString>("expected"); |
|
639 |
||
640 |
QTest::newRow("relativeFile") << "tmp.txt" << false << "."; |
|
641 |
QTest::newRow("relativeFileAbsPath") << "tmp.txt" << true << QDir::currentPath(); |
|
642 |
QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << false << "temp"; |
|
643 |
QTest::newRow("relativeFileInSubDirAbsPath") << "temp/tmp.txt" << true << QDir::currentPath() + "/temp"; |
|
644 |
QTest::newRow("absFilePath") << QDir::currentPath() + "/tmp.txt" << false << QDir::currentPath(); |
|
645 |
QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath(); |
|
646 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << true << ":/tst_qfileinfo/resources"; |
|
647 |
} |
|
648 |
||
649 |
void tst_QFileInfo::dir() |
|
650 |
{ |
|
651 |
QFETCH(QString, file); |
|
652 |
QFETCH(bool, absPath); |
|
653 |
QFETCH(QString, expected); |
|
654 |
||
655 |
QFileInfo fi(file); |
|
656 |
if (absPath) |
|
657 |
QCOMPARE(fi.absolutePath(), expected); |
|
658 |
else |
|
659 |
QCOMPARE(fi.path(), expected); |
|
660 |
} |
|
661 |
||
662 |
||
663 |
void tst_QFileInfo::suffix_data() |
|
664 |
{ |
|
665 |
QTest::addColumn<QString>("file"); |
|
666 |
QTest::addColumn<QString>("expected"); |
|
667 |
||
668 |
QTest::newRow("noextension0") << "file" << ""; |
|
669 |
QTest::newRow("noextension1") << "/path/to/file" << ""; |
|
670 |
QTest::newRow("data0") << "file.tar" << "tar"; |
|
671 |
QTest::newRow("data1") << "file.tar.gz" << "gz"; |
|
672 |
QTest::newRow("data2") << "/path/file/file.tar.gz" << "gz"; |
|
673 |
QTest::newRow("data3") << "/path/file.tar" << "tar"; |
|
674 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "ext1"; |
|
675 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "ext2"; |
|
676 |
QTest::newRow("hidden1") << ".ext1" << "ext1"; |
|
677 |
QTest::newRow("hidden1") << ".ext" << "ext"; |
|
678 |
QTest::newRow("hidden1") << ".ex" << "ex"; |
|
679 |
QTest::newRow("hidden1") << ".e" << "e"; |
|
680 |
QTest::newRow("hidden2") << ".ext1.ext2" << "ext2"; |
|
681 |
QTest::newRow("hidden2") << ".ext.ext2" << "ext2"; |
|
682 |
QTest::newRow("hidden2") << ".ex.ext2" << "ext2"; |
|
683 |
QTest::newRow("hidden2") << ".e.ext2" << "ext2"; |
|
684 |
QTest::newRow("hidden2") << "..ext2" << "ext2"; |
|
685 |
} |
|
686 |
||
687 |
void tst_QFileInfo::suffix() |
|
688 |
{ |
|
689 |
QFETCH(QString, file); |
|
690 |
QFETCH(QString, expected); |
|
691 |
||
692 |
QFileInfo fi(file); |
|
693 |
QCOMPARE(fi.suffix(), expected); |
|
694 |
} |
|
695 |
||
696 |
||
697 |
void tst_QFileInfo::completeSuffix_data() |
|
698 |
{ |
|
699 |
QTest::addColumn<QString>("file"); |
|
700 |
QTest::addColumn<QString>("expected"); |
|
701 |
||
702 |
QTest::newRow("noextension0") << "file" << ""; |
|
703 |
QTest::newRow("noextension1") << "/path/to/file" << ""; |
|
704 |
QTest::newRow("data0") << "file.tar" << "tar"; |
|
705 |
QTest::newRow("data1") << "file.tar.gz" << "tar.gz"; |
|
706 |
QTest::newRow("data2") << "/path/file/file.tar.gz" << "tar.gz"; |
|
707 |
QTest::newRow("data3") << "/path/file.tar" << "tar"; |
|
708 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "ext1"; |
|
709 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "ext1.ext2"; |
|
710 |
} |
|
711 |
||
712 |
void tst_QFileInfo::completeSuffix() |
|
713 |
{ |
|
714 |
QFETCH(QString, file); |
|
715 |
QFETCH(QString, expected); |
|
716 |
||
717 |
QFileInfo fi(file); |
|
718 |
QCOMPARE(fi.completeSuffix(), expected); |
|
719 |
} |
|
720 |
||
721 |
void tst_QFileInfo::baseName_data() |
|
722 |
{ |
|
723 |
QTest::addColumn<QString>("file"); |
|
724 |
QTest::addColumn<QString>("expected"); |
|
725 |
||
726 |
QTest::newRow("data0") << "file.tar" << "file"; |
|
727 |
QTest::newRow("data1") << "file.tar.gz" << "file"; |
|
728 |
QTest::newRow("data2") << "/path/file/file.tar.gz" << "file"; |
|
729 |
QTest::newRow("data3") << "/path/file.tar" << "file"; |
|
730 |
QTest::newRow("data4") << "/path/file" << "file"; |
|
731 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1"; |
|
732 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1"; |
|
733 |
} |
|
734 |
||
735 |
void tst_QFileInfo::baseName() |
|
736 |
{ |
|
737 |
QFETCH(QString, file); |
|
738 |
QFETCH(QString, expected); |
|
739 |
||
740 |
QFileInfo fi(file); |
|
741 |
QCOMPARE(fi.baseName(), expected); |
|
742 |
} |
|
743 |
||
744 |
void tst_QFileInfo::completeBaseName_data() |
|
745 |
{ |
|
746 |
QTest::addColumn<QString>("file"); |
|
747 |
QTest::addColumn<QString>("expected"); |
|
748 |
||
749 |
QTest::newRow("data0") << "file.tar" << "file"; |
|
750 |
QTest::newRow("data1") << "file.tar.gz" << "file.tar"; |
|
751 |
QTest::newRow("data2") << "/path/file/file.tar.gz" << "file.tar"; |
|
752 |
QTest::newRow("data3") << "/path/file.tar" << "file"; |
|
753 |
QTest::newRow("data4") << "/path/file" << "file"; |
|
754 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1"; |
|
755 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1.ext1"; |
|
756 |
} |
|
757 |
||
758 |
void tst_QFileInfo::completeBaseName() |
|
759 |
{ |
|
760 |
QFETCH(QString, file); |
|
761 |
QFETCH(QString, expected); |
|
762 |
||
763 |
QFileInfo fi(file); |
|
764 |
QCOMPARE(fi.completeBaseName(), expected); |
|
765 |
} |
|
766 |
||
767 |
void tst_QFileInfo::permission_data() |
|
768 |
{ |
|
769 |
QTest::addColumn<QString>("file"); |
|
770 |
QTest::addColumn<int>("perms"); |
|
771 |
QTest::addColumn<bool>("expected"); |
|
772 |
||
773 |
QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true; |
|
774 |
QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << int(QFile::ReadUser) << true; |
|
775 |
// QTest::newRow("data2") << "tst_qfileinfo.cpp" << int(QFile::WriteUser) << false; |
|
776 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true; |
|
777 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false; |
|
778 |
QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false; |
|
779 |
} |
|
780 |
||
781 |
void tst_QFileInfo::permission() |
|
782 |
{ |
|
783 |
QFETCH(QString, file); |
|
784 |
QFETCH(int, perms); |
|
785 |
QFETCH(bool, expected); |
|
786 |
#ifdef Q_OS_SYMBIAN |
|
787 |
QSKIP("No user based rights in Symbian OS - SOS needs platform security tests instead", SkipAll); |
|
788 |
#endif |
|
789 |
QFileInfo fi(file); |
|
790 |
QCOMPARE(fi.permission(QFile::Permissions(perms)), expected); |
|
791 |
} |
|
792 |
||
793 |
void tst_QFileInfo::size_data() |
|
794 |
{ |
|
795 |
QTest::addColumn<QString>("file"); |
|
796 |
QTest::addColumn<int>("size"); |
|
797 |
||
798 |
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << 0; |
|
799 |
QFile::remove("file1"); |
|
800 |
QFile file("file1"); |
|
801 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
802 |
QCOMPARE(file.write("JAJAJAA"), qint64(7)); |
|
803 |
QTest::newRow("created-file") << "file1" << 7; |
|
804 |
||
805 |
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << 0; |
|
806 |
} |
|
807 |
||
808 |
void tst_QFileInfo::size() |
|
809 |
{ |
|
810 |
QFETCH(QString, file); |
|
811 |
||
812 |
QFileInfo fi(file); |
|
813 |
(void)fi.permissions(); // see task 104198 |
|
814 |
QTEST(int(fi.size()), "size"); |
|
815 |
} |
|
816 |
||
817 |
void tst_QFileInfo::systemFiles() |
|
818 |
{ |
|
819 |
#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) |
|
820 |
QSKIP("This is a Windows only test", SkipAll); |
|
821 |
#endif |
|
822 |
QFileInfo fi("c:\\pagefile.sys"); |
|
823 |
QVERIFY(fi.exists()); // task 167099 |
|
824 |
QVERIFY(fi.size() > 0); // task 189202 |
|
825 |
QVERIFY(fi.lastModified().isValid()); |
|
826 |
} |
|
827 |
||
828 |
void tst_QFileInfo::compare_data() |
|
829 |
{ |
|
830 |
QTest::addColumn<QString>("file1"); |
|
831 |
QTest::addColumn<QString>("file2"); |
|
832 |
QTest::addColumn<bool>("same"); |
|
833 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
834 |
#if defined(Q_OS_MAC) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
835 |
// Since 10.6 we use realpath() in qfsfileengine, and it properly handles |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
836 |
// file system case sensitivity. However here in the autotest we don't |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
837 |
// check if the file system is case sensitive, so to make it pass in the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
838 |
// default OS X installation we assume we are running on a case insensitive |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
839 |
// file system if on 10.6 and on a case sensitive file system if on 10.5 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
840 |
bool caseSensitiveOnMac = true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
841 |
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
842 |
caseSensitiveOnMac = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
843 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
844 |
|
0 | 845 |
QTest::newRow("data0") |
846 |
<< QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") |
|
847 |
<< QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") |
|
848 |
<< true; |
|
849 |
QTest::newRow("data1") |
|
850 |
<< QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") |
|
851 |
<< QString::fromLatin1("/tst_qfileinfo.cpp") |
|
852 |
<< false; |
|
853 |
QTest::newRow("data2") |
|
854 |
<< QString::fromLatin1("tst_qfileinfo.cpp") |
|
855 |
<< QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") |
|
856 |
<< true; |
|
857 |
QTest::newRow("casesense1") |
|
858 |
<< QString::fromLatin1(SRCDIR "tst_qfileInfo.cpp") |
|
859 |
<< QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") |
|
860 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
861 |
<< true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
862 |
#elif defined(Q_OS_MAC) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
863 |
<< !caseSensitiveOnMac; |
0 | 864 |
#else |
865 |
<< false; |
|
866 |
#endif |
|
867 |
} |
|
868 |
||
869 |
void tst_QFileInfo::compare() |
|
870 |
{ |
|
871 |
QFETCH(QString, file1); |
|
872 |
QFETCH(QString, file2); |
|
873 |
QFETCH(bool, same); |
|
874 |
QFileInfo fi1(file1), fi2(file2); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
875 |
QCOMPARE(fi1 == fi2, same); |
0 | 876 |
} |
877 |
||
878 |
void tst_QFileInfo::consistent_data() |
|
879 |
{ |
|
880 |
QTest::addColumn<QString>("file"); |
|
881 |
QTest::addColumn<QString>("expected"); |
|
882 |
||
883 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
884 |
QTest::newRow("slashes") << QString::fromLatin1("\\a\\a\\a\\a") << QString::fromLatin1("/a/a/a/a"); |
|
885 |
#endif |
|
886 |
QTest::newRow("ending slash") << QString::fromLatin1("/a/somedir/") << QString::fromLatin1("/a/somedir/"); |
|
887 |
QTest::newRow("no ending slash") << QString::fromLatin1("/a/somedir") << QString::fromLatin1("/a/somedir"); |
|
888 |
} |
|
889 |
||
890 |
void tst_QFileInfo::consistent() |
|
891 |
{ |
|
892 |
QFETCH(QString, file); |
|
893 |
QFETCH(QString, expected); |
|
894 |
||
895 |
QFileInfo fi(file); |
|
896 |
QCOMPARE(fi.filePath(), expected); |
|
897 |
QCOMPARE(fi.dir().path() + "/" + fi.fileName(), expected); |
|
898 |
} |
|
899 |
||
900 |
||
901 |
void tst_QFileInfo::fileTimes_data() |
|
902 |
{ |
|
903 |
QTest::addColumn<QString>("fileName"); |
|
904 |
QTest::newRow("simple") << QString::fromLatin1("simplefile.txt"); |
|
905 |
QTest::newRow( "longfile" ) << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" |
|
906 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
907 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
908 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
909 |
"longFileNamelongFileNamelongFileNamelongFileName.txt"); |
|
910 |
QTest::newRow( "longfile absolutepath" ) << QFileInfo(QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" |
|
911 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
912 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
913 |
"longFileNamelongFileNamelongFileNamelongFileName" |
|
914 |
"longFileNamelongFileNamelongFileNamelongFileName.txt")).absoluteFilePath(); |
|
915 |
} |
|
916 |
||
917 |
void tst_QFileInfo::fileTimes() |
|
918 |
{ |
|
919 |
#if defined(Q_OS_WINCE) |
|
920 |
int sleepTime = 3000; |
|
921 |
#else |
|
922 |
int sleepTime = 2000; |
|
923 |
#endif |
|
924 |
QFETCH(QString, fileName); |
|
925 |
if (QFile::exists(fileName)) { |
|
926 |
QVERIFY(QFile::remove(fileName)); |
|
927 |
} |
|
928 |
QTest::qSleep(sleepTime); |
|
929 |
{ |
|
930 |
QFile file(fileName); |
|
931 |
#if defined(Q_OS_WINCE) |
|
932 |
QEXPECT_FAIL("longfile", "No long filenames on WinCE", Abort); |
|
933 |
QEXPECT_FAIL("longfile absolutepath", "No long filenames on WinCE", Abort); |
|
934 |
#elif defined(Q_OS_SYMBIAN) |
|
935 |
QEXPECT_FAIL("longfile", "Maximum total filepath cannot exceed 256 characters in Symbian", Abort); |
|
936 |
QEXPECT_FAIL("longfile absolutepath", "Maximum total filepath cannot exceed 256 characters in Symbian", Abort); |
|
937 |
#endif |
|
938 |
QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); |
|
939 |
QTextStream ts(&file); |
|
940 |
ts << fileName << endl; |
|
941 |
} |
|
942 |
QTest::qSleep(sleepTime); |
|
943 |
QDateTime beforeWrite = QDateTime::currentDateTime(); |
|
944 |
QTest::qSleep(sleepTime); |
|
945 |
{ |
|
946 |
QFileInfo fileInfo(fileName); |
|
947 |
QVERIFY(fileInfo.created() < beforeWrite); |
|
948 |
QFile file(fileName); |
|
949 |
QVERIFY(file.open(QFile::ReadWrite | QFile::Text)); |
|
950 |
QTextStream ts(&file); |
|
951 |
ts << fileName << endl; |
|
952 |
} |
|
953 |
QTest::qSleep(sleepTime); |
|
954 |
QDateTime beforeRead = QDateTime::currentDateTime(); |
|
955 |
QTest::qSleep(sleepTime); |
|
956 |
{ |
|
957 |
QFileInfo fileInfo(fileName); |
|
958 |
// On unix created() returns the same as lastModified(). |
|
959 |
#if !defined(Q_OS_UNIX) && !defined(Q_OS_WINCE) |
|
960 |
QVERIFY(fileInfo.created() < beforeWrite); |
|
961 |
#endif |
|
962 |
QVERIFY(fileInfo.lastModified() > beforeWrite); |
|
963 |
QFile file(fileName); |
|
964 |
QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); |
|
965 |
QTextStream ts(&file); |
|
966 |
QString line = ts.readLine(); |
|
967 |
QCOMPARE(line, fileName); |
|
968 |
} |
|
969 |
||
970 |
QFileInfo fileInfo(fileName); |
|
971 |
#if !defined(Q_OS_UNIX) && !defined(Q_OS_WINCE) |
|
972 |
QVERIFY(fileInfo.created() < beforeWrite); |
|
973 |
#endif |
|
974 |
//In Vista the last-access timestamp is not updated when the file is accessed/touched (by default). |
|
975 |
//To enable this the HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisableLastAccessUpdate |
|
976 |
//is set to 0, in the test machine. |
|
977 |
#ifdef Q_OS_WINCE |
|
978 |
QEXPECT_FAIL("simple", "WinCE only stores date of access data, not the time", Continue); |
|
979 |
#endif |
|
980 |
#ifdef Q_OS_SYMBIAN |
|
981 |
QEXPECT_FAIL("simple", "Symbian implementation of stat doesn't return read time right", Abort); |
|
982 |
#endif |
|
983 |
QVERIFY(fileInfo.lastRead() > beforeRead); |
|
984 |
QVERIFY(fileInfo.lastModified() > beforeWrite); |
|
985 |
QVERIFY(fileInfo.lastModified() < beforeRead); |
|
986 |
} |
|
987 |
||
988 |
void tst_QFileInfo::fileTimes_oldFile() |
|
989 |
{ |
|
990 |
// This is not supported on WinCE |
|
991 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
992 |
// All files are opened in share mode (both read and write). |
|
993 |
DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; |
|
994 |
||
995 |
// All files on Windows can be read; there's no such thing as an |
|
996 |
// unreadable file. Add GENERIC_WRITE if WriteOnly is passed. |
|
997 |
int accessRights = GENERIC_READ | GENERIC_WRITE; |
|
998 |
||
999 |
SECURITY_ATTRIBUTES securityAtts = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; |
|
1000 |
||
1001 |
// Regular file mode. In Unbuffered mode, pass the no-buffering flag. |
|
1002 |
DWORD flagsAndAtts = FILE_ATTRIBUTE_NORMAL; |
|
1003 |
||
1004 |
// WriteOnly can create files, ReadOnly cannot. |
|
1005 |
DWORD creationDisp = OPEN_ALWAYS; |
|
1006 |
||
1007 |
// Create the file handle. |
|
1008 |
HANDLE fileHandle = CreateFile(L"oldfile.txt", |
|
1009 |
accessRights, |
|
1010 |
shareMode, |
|
1011 |
&securityAtts, |
|
1012 |
creationDisp, |
|
1013 |
flagsAndAtts, |
|
1014 |
NULL); |
|
1015 |
||
1016 |
// Set file times back to 1601. |
|
1017 |
SYSTEMTIME stime; |
|
1018 |
stime.wYear = 1601; |
|
1019 |
stime.wMonth = 1; |
|
1020 |
stime.wDayOfWeek = 1; |
|
1021 |
stime.wDay = 1; |
|
1022 |
stime.wHour = 1; |
|
1023 |
stime.wMinute = 0; |
|
1024 |
stime.wSecond = 0; |
|
1025 |
stime.wMilliseconds = 0; |
|
1026 |
||
1027 |
FILETIME ctime; |
|
1028 |
QVERIFY(SystemTimeToFileTime(&stime, &ctime)); |
|
1029 |
FILETIME atime = ctime; |
|
1030 |
FILETIME mtime = atime; |
|
1031 |
QVERIFY(fileHandle); |
|
1032 |
QVERIFY(SetFileTime(fileHandle, &ctime, &atime, &mtime) != 0); |
|
1033 |
||
1034 |
CloseHandle(fileHandle); |
|
1035 |
||
1036 |
QFileInfo info("oldfile.txt"); |
|
1037 |
QCOMPARE(info.lastModified(), QDateTime(QDate(1601, 1, 1), QTime(1, 0), Qt::UTC).toLocalTime()); |
|
1038 |
#endif |
|
1039 |
} |
|
1040 |
||
1041 |
void tst_QFileInfo::isSymLink_data() |
|
1042 |
{ |
|
1043 |
QFile::remove("link.lnk"); |
|
1044 |
QFile::remove("brokenlink.lnk"); |
|
1045 |
QFile::remove("dummyfile"); |
|
1046 |
||
1047 |
QFile file1(SRCDIR "tst_qfileinfo.cpp"); |
|
1048 |
QVERIFY(file1.link("link.lnk")); |
|
1049 |
||
1050 |
QFile file2("dummyfile"); |
|
1051 |
file2.open(QIODevice::WriteOnly); |
|
1052 |
QVERIFY(file2.link("brokenlink.lnk")); |
|
1053 |
file2.remove(); |
|
1054 |
||
1055 |
QTest::addColumn<QString>("path"); |
|
1056 |
QTest::addColumn<bool>("isSymLink"); |
|
1057 |
QTest::addColumn<QString>("linkTarget"); |
|
1058 |
||
1059 |
QTest::newRow("existent file") << SRCDIR "tst_qfileinfo.cpp" << false << ""; |
|
1060 |
QTest::newRow("link") << "link.lnk" << true << QFileInfo(SRCDIR "tst_qfileinfo.cpp").absoluteFilePath(); |
|
1061 |
QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); |
|
1062 |
} |
|
1063 |
||
1064 |
void tst_QFileInfo::isSymLink() |
|
1065 |
{ |
|
1066 |
QFETCH(QString, path); |
|
1067 |
QFETCH(bool, isSymLink); |
|
1068 |
QFETCH(QString, linkTarget); |
|
1069 |
||
1070 |
QFileInfo fi(path); |
|
1071 |
QCOMPARE(fi.isSymLink(), isSymLink); |
|
1072 |
QCOMPARE(fi.symLinkTarget(), linkTarget); |
|
1073 |
} |
|
1074 |
||
1075 |
void tst_QFileInfo::isHidden_data() |
|
1076 |
{ |
|
1077 |
QTest::addColumn<QString>("path"); |
|
1078 |
QTest::addColumn<bool>("isHidden"); |
|
1079 |
foreach (const QFileInfo& info, QDir::drives()) { |
|
1080 |
QTest::newRow(qPrintable("drive." + info.path())) << info.path() << false; |
|
1081 |
} |
|
1082 |
||
1083 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1084 |
QVERIFY(QDir("./hidden-directory").exists() || QDir().mkdir("./hidden-directory")); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1085 |
QVERIFY(SetFileAttributesW(reinterpret_cast<LPCWSTR>(QString("./hidden-directory").utf16()),FILE_ATTRIBUTE_HIDDEN)); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1086 |
QTest::newRow("C:/path/to/hidden-directory") << QDir::currentPath() + QString::fromLatin1("/hidden-directory") << true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1087 |
QTest::newRow("C:/path/to/hidden-directory/.") << QDir::currentPath() + QString::fromLatin1("/hidden-directory/.") << true; |
0 | 1088 |
#endif |
1089 |
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1090 |
QVERIFY(QDir("./.hidden-directory").exists() || QDir().mkdir("./.hidden-directory")); |
0 | 1091 |
QTest::newRow("/path/to/.hidden-directory") << QDir::currentPath() + QString("/.hidden-directory") << true; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1092 |
QTest::newRow("/path/to/.hidden-directory/.") << QDir::currentPath() + QString("/.hidden-directory/.") << true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1093 |
QTest::newRow("/path/to/.hidden-directory/..") << QDir::currentPath() + QString("/.hidden-directory/..") << true; |
0 | 1094 |
#endif |
1095 |
||
1096 |
#if defined(Q_OS_MAC) |
|
1097 |
// /bin has the hidden attribute on Mac OS X |
|
1098 |
QTest::newRow("/bin/") << QString::fromLatin1("/bin/") << true; |
|
1099 |
#elif !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN) |
|
1100 |
QTest::newRow("/bin/") << QString::fromLatin1("/bin/") << false; |
|
1101 |
#endif |
|
1102 |
||
1103 |
#ifdef Q_OS_MAC |
|
1104 |
QTest::newRow("mac_etc") << QString::fromLatin1("/etc") << true; |
|
1105 |
QTest::newRow("mac_private_etc") << QString::fromLatin1("/private/etc") << false; |
|
1106 |
QTest::newRow("mac_Applications") << QString::fromLatin1("/Applications") << false; |
|
1107 |
#endif |
|
1108 |
||
1109 |
#ifdef Q_OS_SYMBIAN |
|
1110 |
// No guaranteed hidden file knows to exist in Symbian filesystem, so make one. |
|
1111 |
QString hiddenFileName("hidden.txt"); |
|
1112 |
QString notHiddenFileName("nothidden.txt"); |
|
1113 |
QTest::newRow("hidden file") << hiddenFileName << true; |
|
1114 |
QTest::newRow("non-hidden file") << notHiddenFileName << false; |
|
1115 |
||
1116 |
{ |
|
1117 |
QFile file(hiddenFileName); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1118 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1119 |
QTextStream t(&file); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1120 |
t << "foobar"; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1121 |
|
0 | 1122 |
QFile file2(notHiddenFileName); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1123 |
QVERIFY(file2.open(QIODevice::WriteOnly)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1124 |
QTextStream t2(&file2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1125 |
t2 << "foobar"; |
0 | 1126 |
} |
1127 |
||
1128 |
RFs rfs; |
|
1129 |
TInt err = rfs.Connect(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1130 |
QCOMPARE(err, KErrNone); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1131 |
HBufC* symFile = qt_QString2HBufC(hiddenFileName); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1132 |
err = rfs.SetAtt(*symFile, KEntryAttHidden, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1133 |
rfs.Close(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1134 |
delete symFile; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1135 |
QCOMPARE(err, KErrNone); |
0 | 1136 |
#endif |
1137 |
} |
|
1138 |
||
1139 |
void tst_QFileInfo::isHidden() |
|
1140 |
{ |
|
1141 |
QFETCH(QString, path); |
|
1142 |
QFETCH(bool, isHidden); |
|
1143 |
QFileInfo fi(path); |
|
1144 |
||
1145 |
QCOMPARE(fi.isHidden(), isHidden); |
|
1146 |
} |
|
1147 |
||
1148 |
void tst_QFileInfo::isBundle_data() |
|
1149 |
{ |
|
1150 |
QTest::addColumn<QString>("path"); |
|
1151 |
QTest::addColumn<bool>("isBundle"); |
|
1152 |
QTest::newRow("root") << QString::fromLatin1("/") << false; |
|
1153 |
#ifdef Q_OS_MAC |
|
1154 |
QTest::newRow("mac_Applications") << QString::fromLatin1("/Applications") << false; |
|
1155 |
QTest::newRow("mac_Applications") << QString::fromLatin1("/Applications/Safari.app") << true; |
|
1156 |
#endif |
|
1157 |
} |
|
1158 |
||
1159 |
void tst_QFileInfo::isBundle() |
|
1160 |
{ |
|
1161 |
QFETCH(QString, path); |
|
1162 |
QFETCH(bool, isBundle); |
|
1163 |
QFileInfo fi(path); |
|
1164 |
QCOMPARE(fi.isBundle(), isBundle); |
|
1165 |
} |
|
1166 |
||
1167 |
void tst_QFileInfo::isLocalFs_data() |
|
1168 |
{ |
|
1169 |
QTest::addColumn<QString>("path"); |
|
1170 |
QTest::addColumn<bool>("isLocalFs"); |
|
1171 |
||
1172 |
QTest::newRow("local root") << QString::fromLatin1("/") << true; |
|
1173 |
QTest::newRow("local non-existent file") << QString::fromLatin1("/abrakadabra.boo") << true; |
|
1174 |
||
1175 |
QTest::newRow("qresource root") << QString::fromLatin1(":/") << false; |
|
1176 |
} |
|
1177 |
||
1178 |
void tst_QFileInfo::isLocalFs() |
|
1179 |
{ |
|
1180 |
QFETCH(QString, path); |
|
1181 |
QFETCH(bool, isLocalFs); |
|
1182 |
||
1183 |
QFileInfo info(path); |
|
1184 |
QFileInfoPrivate *privateInfo = getPrivate(info); |
|
1185 |
QVERIFY(privateInfo->data->fileEngine); |
|
1186 |
QCOMPARE(bool(privateInfo->data->fileEngine->fileFlags(QAbstractFileEngine::LocalDiskFlag) |
|
1187 |
& QAbstractFileEngine::LocalDiskFlag), isLocalFs); |
|
1188 |
} |
|
1189 |
||
1190 |
void tst_QFileInfo::refresh() |
|
1191 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1192 |
#if defined(Q_OS_WINCE) || defined(Q_OS_WIN) |
0 | 1193 |
int sleepTime = 3000; |
1194 |
#else |
|
1195 |
int sleepTime = 2000; |
|
1196 |
#endif |
|
1197 |
||
1198 |
QFile::remove("file1"); |
|
1199 |
QFile file("file1"); |
|
1200 |
QVERIFY(file.open(QFile::WriteOnly)); |
|
1201 |
QCOMPARE(file.write("JAJAJAA"), qint64(7)); |
|
1202 |
file.flush(); |
|
1203 |
||
1204 |
QFileInfo info(file); |
|
1205 |
QDateTime lastModified = info.lastModified(); |
|
1206 |
QCOMPARE(info.size(), qint64(7)); |
|
1207 |
||
1208 |
QTest::qSleep(sleepTime); |
|
1209 |
||
1210 |
QCOMPARE(file.write("JOJOJO"), qint64(6)); |
|
1211 |
file.flush(); |
|
1212 |
QVERIFY(info.lastModified() == lastModified); |
|
1213 |
||
1214 |
QCOMPARE(info.size(), qint64(7)); |
|
1215 |
#if defined(Q_OS_WIN) || defined(Q_OS_WINCE) |
|
1216 |
if (QSysInfo::windowsVersion() & QSysInfo::WV_VISTA || |
|
1217 |
QSysInfo::windowsVersion() & QSysInfo::WV_CE_based) |
|
1218 |
file.close(); |
|
1219 |
#endif |
|
1220 |
#if defined(Q_OS_WINCE) |
|
1221 |
// On Windows CE we need to close the file. |
|
1222 |
// Otherwise the content will be cached and not |
|
1223 |
// flushed to the storage, although we flushed it |
|
1224 |
// manually!!! CE has interim cache, we cannot influence. |
|
1225 |
QTest::qWait(5000); |
|
1226 |
#endif |
|
1227 |
info.refresh(); |
|
1228 |
QCOMPARE(info.size(), qint64(13)); |
|
1229 |
QVERIFY(info.lastModified() > lastModified); |
|
1230 |
||
1231 |
QFileInfo info2 = info; |
|
1232 |
QCOMPARE(info2.size(), info.size()); |
|
1233 |
||
1234 |
info2.refresh(); |
|
1235 |
QCOMPARE(info2.size(), info.size()); |
|
1236 |
} |
|
1237 |
||
1238 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) |
|
1239 |
void tst_QFileInfo::brokenShortcut() |
|
1240 |
{ |
|
1241 |
QString linkName("borkenlink.lnk"); |
|
1242 |
QFile::remove(linkName); |
|
1243 |
QFile file(linkName); |
|
1244 |
file.open(QFile::WriteOnly); |
|
1245 |
file.write("b0rk"); |
|
1246 |
file.close(); |
|
1247 |
||
1248 |
QFileInfo info(linkName); |
|
1249 |
QVERIFY(info.isSymLink()); |
|
1250 |
QVERIFY(!info.exists()); |
|
1251 |
QFile::remove(linkName); |
|
1252 |
} |
|
1253 |
#endif |
|
1254 |
||
1255 |
void tst_QFileInfo::isWritable() |
|
1256 |
{ |
|
1257 |
#ifdef Q_OS_SYMBIAN |
|
1258 |
QSKIP("Currently skipped on Symbian OS, but surely there is a writeable file somewhere???", SkipAll); |
|
1259 |
#endif |
|
1260 |
||
1261 |
QFile tempfile("tempfile.txt"); |
|
1262 |
tempfile.open(QIODevice::WriteOnly); |
|
1263 |
tempfile.write("This file is generated by the QFileInfo autotest."); |
|
1264 |
tempfile.close(); |
|
1265 |
||
1266 |
QVERIFY(QFileInfo("tempfile.txt").isWritable()); |
|
1267 |
tempfile.remove(); |
|
1268 |
||
1269 |
#ifdef Q_OS_WIN |
|
1270 |
#ifdef Q_OS_WINCE |
|
1271 |
QFileInfo fi("\\Windows\\wince.nls"); |
|
1272 |
#else |
|
1273 |
QFileInfo fi("c:\\pagefile.sys"); |
|
1274 |
#endif |
|
1275 |
QVERIFY(fi.exists()); |
|
1276 |
QVERIFY(!fi.isWritable()); |
|
1277 |
#endif |
|
1278 |
#ifdef Q_OS_UNIX |
|
1279 |
if (::getuid() == 0) |
|
1280 |
QVERIFY(QFileInfo("/etc/passwd").isWritable()); |
|
1281 |
else |
|
1282 |
QVERIFY(!QFileInfo("/etc/passwd").isWritable()); |
|
1283 |
#endif |
|
1284 |
} |
|
1285 |
||
1286 |
void tst_QFileInfo::isExecutable() |
|
1287 |
{ |
|
1288 |
#ifdef Q_OS_SYMBIAN |
|
1289 |
# if defined(Q_CC_NOKIAX86) |
|
1290 |
QSKIP("Impossible to implement reading/touching of application binaries in Symbian emulator", SkipAll); |
|
1291 |
# endif |
|
1292 |
QString appPath = "c:/sys/bin/tst_qfileinfo.exe"; |
|
1293 |
#else |
|
1294 |
QString appPath = QCoreApplication::applicationDirPath(); |
|
1295 |
appPath += "/tst_qfileinfo"; |
|
1296 |
# if defined(Q_OS_WIN) |
|
1297 |
appPath += ".exe"; |
|
1298 |
# endif |
|
1299 |
#endif |
|
1300 |
QFileInfo fi(appPath); |
|
1301 |
QCOMPARE(fi.isExecutable(), true); |
|
1302 |
||
1303 |
QCOMPARE(QFileInfo("qfileinfo.pro").isExecutable(), false); |
|
1304 |
} |
|
1305 |
||
1306 |
||
1307 |
void tst_QFileInfo::testDecomposedUnicodeNames_data() |
|
1308 |
{ |
|
1309 |
QTest::addColumn<QString>("filePath"); |
|
1310 |
QTest::addColumn<QString>("fileName"); |
|
1311 |
QTest::addColumn<bool>("exists"); |
|
1312 |
QString currPath = QDir::currentPath(); |
|
1313 |
QTest::newRow("latin-only") << currPath + "/4.pdf" << "4.pdf" << true; |
|
1314 |
QTest::newRow("one-decomposed uni") << currPath + QString::fromUtf8("/4 ä.pdf") << QString::fromUtf8("4 ä.pdf") << true; |
|
1315 |
QTest::newRow("many-decomposed uni") << currPath + QString::fromUtf8("/4 äääcopy.pdf") << QString::fromUtf8("4 äääcopy.pdf") << true; |
|
1316 |
QTest::newRow("no decomposed") << currPath + QString::fromUtf8("/4 øøøcopy.pdf") << QString::fromUtf8("4 øøøcopy.pdf") << true; |
|
1317 |
} |
|
1318 |
||
1319 |
static void createFileNative(const QString &filePath) |
|
1320 |
{ |
|
1321 |
#ifdef Q_OS_UNIX |
|
1322 |
int fd = open(filePath.normalized(QString::NormalizationForm_D).toUtf8().constData(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); |
|
1323 |
if (fd < 0) { |
|
1324 |
QFAIL("couldn't create file"); |
|
1325 |
} else { |
|
1326 |
close(fd); |
|
1327 |
} |
|
1328 |
#else |
|
1329 |
Q_UNUSED(filePath); |
|
1330 |
#endif |
|
1331 |
} |
|
1332 |
||
1333 |
static void removeFileNative(const QString &filePath) |
|
1334 |
{ |
|
1335 |
#ifdef Q_OS_UNIX |
|
1336 |
unlink(filePath.normalized(QString::NormalizationForm_D).toUtf8().constData()); |
|
1337 |
#else |
|
1338 |
Q_UNUSED(filePath); |
|
1339 |
#endif |
|
1340 |
} |
|
1341 |
||
1342 |
void tst_QFileInfo::testDecomposedUnicodeNames() |
|
1343 |
{ |
|
1344 |
#ifndef Q_OS_MAC |
|
1345 |
QSKIP("This is a OS X only test (unless you know more about filesystems, then maybe you should try it ;)", SkipAll); |
|
1346 |
#endif |
|
1347 |
QFETCH(QString, filePath); |
|
1348 |
createFileNative(filePath); |
|
1349 |
||
1350 |
QFileInfo file(filePath); |
|
1351 |
QTEST(file.fileName(), "fileName"); |
|
1352 |
QTEST(file.exists(), "exists"); |
|
1353 |
removeFileNative(filePath); |
|
1354 |
} |
|
1355 |
||
1356 |
void tst_QFileInfo::equalOperator() const |
|
1357 |
{ |
|
1358 |
/* Compare two default constructed values. Yes, to me it seems it should be the opposite too, but |
|
1359 |
* this is how the code was written. */ |
|
1360 |
QVERIFY(!(QFileInfo() == QFileInfo())); |
|
1361 |
} |
|
1362 |
||
1363 |
||
1364 |
void tst_QFileInfo::equalOperatorWithDifferentSlashes() const |
|
1365 |
{ |
|
1366 |
const QFileInfo fi1("/usr"); |
|
1367 |
const QFileInfo fi2("/usr/"); |
|
1368 |
||
1369 |
QCOMPARE(fi1, fi2); |
|
1370 |
} |
|
1371 |
||
1372 |
void tst_QFileInfo::notEqualOperator() const |
|
1373 |
{ |
|
1374 |
/* Compare two default constructed values. Yes, to me it seems it should be the opposite too, but |
|
1375 |
* this is how the code was written. */ |
|
1376 |
QVERIFY(QFileInfo() != QFileInfo()); |
|
1377 |
} |
|
1378 |
||
1379 |
QTEST_MAIN(tst_QFileInfo) |
|
1380 |
#include "tst_qfileinfo.moc" |