┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/testdir.cpp
diff options
context:
space:
mode:
authorSebastian Englbrecht <[email protected]>2026-06-01 18:22:54 +0200
committerMéven Car <[email protected]>2026-06-18 10:05:59 +0000
commit5cd0c642f59924babe66d017d7c0ced7934de3d3 (patch)
treea182680c067516ca5e91a8c67fd9eabf2cd4698d /src/tests/testdir.cpp
parent91e7c0c1e032b6e3e0558b8048fce6a3b68d297a (diff)
tests: fix or skip tests on windows
Diffstat (limited to 'src/tests/testdir.cpp')
-rw-r--r--src/tests/testdir.cpp27
1 files changed, 21 insertions, 6 deletions
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 <utime.h>
-#else
-#include <sys/utime.h>
+#elif defined(Q_OS_WIN)
+#include <windows.h>
#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<const wchar_t *>(path.utf16()), &utbuf);
+ HANDLE h = CreateFileW(reinterpret_cast<const wchar_t *>(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<DWORD>(fileTime & 0xFFFFFFFF);
+ ft.dwHighDateTime = static_cast<DWORD>((fileTime >> 32) & 0xFFFFFFFF);
+ SetFileTime(h, nullptr, nullptr, &ft);
+ CloseHandle(h);
+ }
#endif
}