diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-08-04 16:10:09 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-08-05 16:41:32 +0000 |
commit | 261c6713bd0b39778236f7dbb1d81d48599f955c (patch) | |
tree | a1f05cfebf4258bd416a1b0d17dca0c1581ca1c6 /tests | |
parent | 88c30618d512864adab0733b58dd5f48b7f98f74 (diff) |
Introduce QFileInfo::birthTime and metadataChangeTime
[ChangeLog][QtCore][QFileInfo] Deprecated created() because it could
return one of three different file times depending on the OS and
filesystem type, without the ability to determine which one is which. It
is replaced by metadataChangeTime() and birthTime().
[ChangeLog][QtCore][QFileInfo] Added QFileInfo::metadataChangeTime(),
which returns the time the file's metadata was last changed, if it is
known, and falling back to the same value as lastModified() otherwise.
On Unix systems, this corresponds to the file's ctime.
[ChangeLog][QtCore][QFileInfo] Added QFileInfo::birthTime(), which
returns the file's birth time if it is known, an invalid QDateTime
otherwise. This function is supported on Windows and on some Unix
systems.
Change-Id: I0031aa609e714ae983c3fffd1467bd8b3e3a593d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 4c015be5aa..b269e3e1e4 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1034,6 +1034,11 @@ void tst_QFileInfo::systemFiles() QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QVERIFY(fi.size() > 0); QVERIFY(fi.lastModified().isValid()); + QVERIFY(fi.metadataChangeTime().isValid()); + QCOMPARE(fi.metadataChangeTime(), fi.lastModified()); // On Windows, they're the same + QVERIFY(fi.birthTime().isValid()); + QVERIFY(fi.birthTime() <= fi.lastModified()); + QCOMPARE(fi.created(), fi.birthTime()); // On Windows, they're the same } void tst_QFileInfo::compare_data() @@ -1145,6 +1150,8 @@ void tst_QFileInfo::fileTimes() QTest::qSleep(sleepTime); { QFileInfo fileInfo(fileName); + QVERIFY(!fileInfo.birthTime().isValid() || fileInfo.birthTime() < beforeWrite); + QVERIFY(fileInfo.metadataChangeTime() < beforeWrite); QVERIFY(fileInfo.created() < beforeWrite); QFile file(fileName); QVERIFY(file.open(QFile::ReadWrite | QFile::Text)); @@ -1156,10 +1163,8 @@ void tst_QFileInfo::fileTimes() QTest::qSleep(sleepTime); { QFileInfo fileInfo(fileName); -// On unix created() returns the same as lastModified(). -#if !defined(Q_OS_UNIX) - QVERIFY(fileInfo.created() < beforeWrite); -#endif + QVERIFY(!fileInfo.birthTime().isValid() || fileInfo.birthTime() < beforeWrite); + QVERIFY(fileInfo.metadataChangeTime() > beforeWrite); QVERIFY(fileInfo.lastModified() > beforeWrite); QFile file(fileName); QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); @@ -1169,9 +1174,9 @@ void tst_QFileInfo::fileTimes() } QFileInfo fileInfo(fileName); -#if !defined(Q_OS_UNIX) - QVERIFY(fileInfo.created() < beforeWrite); -#endif + QVERIFY(!fileInfo.birthTime().isValid() || fileInfo.birthTime() < beforeWrite); + QVERIFY(fileInfo.metadataChangeTime() > beforeWrite); + //In Vista the last-access timestamp is not updated when the file is accessed/touched (by default). //To enable this the HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisableLastAccessUpdate //is set to 0, in the test machine. @@ -1901,6 +1906,8 @@ void tst_QFileInfo::invalidState() info.setCaching(false); info.created(); + info.birthTime(); + info.metadataChangeTime(); info.lastRead(); info.lastModified(); } @@ -1913,6 +1920,8 @@ void tst_QFileInfo::invalidState() info.setCaching(false); info.created(); + info.birthTime(); + info.metadataChangeTime(); info.lastRead(); info.lastModified(); } @@ -1925,6 +1934,8 @@ void tst_QFileInfo::invalidState() info.setCaching(false); info.created(); + info.birthTime(); + info.metadataChangeTime(); info.lastRead(); info.lastModified(); } @@ -1937,6 +1948,8 @@ void tst_QFileInfo::nonExistingFileDates() QFileInfo info("non-existing-file.foobar"); QVERIFY(!info.exists()); QVERIFY(!info.created().isValid()); + QVERIFY(!info.birthTime().isValid()); + QVERIFY(!info.metadataChangeTime().isValid()); QVERIFY(!info.lastRead().isValid()); QVERIFY(!info.lastModified().isValid()); } |