Make tst_QFileInfo::setFileTimes more robust
There are some systems that do not support millisecond resolution in timestamps. An example of such system is VxWorks. POSIX2008 demands that `stat` contains an `st_mtim` field of type `timespec`. That field holds modification time with a nanosecond resolution. VxWorks reports _POSIX_VERSION as 200112. The `stat` struct does not contain `st_mtim`, but rather an `st_mtime` which holds a `time_t` which contains seconds. This leads to setFileTimes failing, because the test tries to save the current datetime as the modification time of a file, but the ms part is cut off. Fix the problem by checking if the timestamp read back from the filesystem contains milliseconds and only check it if it's not zero. Pick-to: 6.7 Task-number: QTBUG-115777 Change-Id: I8c8a3b1c8e97955f13f059bcebf66d1b5af174fe Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
785a5e6eb4
commit
88cb405514
@ -1217,9 +1217,16 @@ void tst_QFileInfo::setFileTimes()
|
||||
QCOMPARE(file.write(data), data.size());
|
||||
QCOMPARE(file.size(), data.size());
|
||||
|
||||
const QDateTime before = QDateTime::currentDateTimeUtc().addMSecs(-5000);
|
||||
QDateTime before = QDateTime::currentDateTimeUtc().addMSecs(-5000);
|
||||
|
||||
QVERIFY(file.setFileTime(before, QFile::FileModificationTime));
|
||||
const QDateTime mtime = file.fileTime(QFile::FileModificationTime).toUTC();
|
||||
if (mtime.time().msec() == 0)
|
||||
{
|
||||
const QTime beforeTime = before.time();
|
||||
const QTime beforeTimeWithMSCutOff{beforeTime.hour(), beforeTime.minute(), beforeTime.second(), 0};
|
||||
before.setTime(beforeTimeWithMSCutOff);
|
||||
}
|
||||
QCOMPARE(mtime, before);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user