From 5cd0c642f59924babe66d017d7c0ced7934de3d3 Mon Sep 17 00:00:00 2001 From: Sebastian Englbrecht Date: Mon, 1 Jun 2026 18:22:54 +0200 Subject: tests: fix or skip tests on windows --- src/tests/testdir.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/tests/testdir.cpp') diff --git a/src/tests/testdir.cpp b/src/tests/testdir.cpp index cd35ac748..84e76e712 100644 --- a/src/tests/testdir.cpp +++ b/src/tests/testdir.cpp @@ -8,8 +8,8 @@ #ifdef Q_OS_UNIX #include -#else -#include +#elif defined(Q_OS_WIN) +#include #endif TestDir::TestDir(const QString &directoryPrefix) @@ -33,10 +33,25 @@ static void setTimeStamp(const QString &path, const QDateTime &mtime) utbuf.modtime = utbuf.actime; utime(QFile::encodeName(path), &utbuf); #elif defined(Q_OS_WIN) - struct _utimbuf utbuf; - utbuf.actime = mtime.toSecsSinceEpoch(); - utbuf.modtime = utbuf.actime; - _wutime(reinterpret_cast(path.utf16()), &utbuf); + HANDLE h = CreateFileW(reinterpret_cast(path.utf16()), + FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, // required to open directories + nullptr); + if (h != INVALID_HANDLE_VALUE) { + // Convert a Unix-epoch time in milliseconds to a Windows FILETIME, which + // counts 100-nanosecond intervals since 1601-01-01. + // 11644473600000: milliseconds between 1601-01-01 and the Unix epoch (1970-01-01). + // 10000: 100-nanosecond intervals per millisecond. + qint64 fileTime = (mtime.toMSecsSinceEpoch() + 11644473600000LL) * 10000LL; + FILETIME ft; + ft.dwLowDateTime = static_cast(fileTime & 0xFFFFFFFF); + ft.dwHighDateTime = static_cast((fileTime >> 32) & 0xFFFFFFFF); + SetFileTime(h, nullptr, nullptr, &ft); + CloseHandle(h); + } #endif } -- cgit v1.3.1