From 88cb405514270a320d2993e8fb1c7b7b62646112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Matysiak?= Date: Tue, 14 May 2024 18:09:07 +0200 Subject: [PATCH] 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 --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index f7d531f61f8..563e4c2a83d 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -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); }