summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2021-05-31 16:25:21 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2021-06-05 01:16:06 +0200
commitded82d1b073adb769afd28104515d240e8e1dd3f (patch)
tree933acea7f79e2e21af71e9e38c37868974a87d7e /tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
parent0564ebdb3641d7325f73dbbf2cbb04e6dca92d83 (diff)
Implement QFileInfo::junctionTarget(), adjust auto-test
The change in 004e3e0dc2cab4a4534d2ed3ace41aad6bfbe45d introduces Windows junction awareness, though users were still unable to resolve the junction target. This change adds the ability to solve this. Fixes: QTBUG-93869 Change-Id: I9f4d4ed87b92e757f7b6d8739e2a61b58c096f63 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 916b084e24..4d74fe4d98 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -1782,14 +1782,36 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks()
}
}
});
- const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString();
- const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString();
+ const QString actualCanonicalFilePath = fi.canonicalFilePath();
QCOMPARE(fi.isJunction(), isJunction);
QCOMPARE(fi.isSymbolicLink(), isSymLink);
if (isSymLink) {
- QCOMPARE(actualSymLinkTarget, linkTarget);
+ QCOMPARE(fi.symLinkTarget(), linkTarget);
QCOMPARE(actualCanonicalFilePath, canonicalFilePath);
}
+
+ if (isJunction) {
+ if (creationResult.target.startsWith(uR"(\??\)"))
+ creationResult.target = creationResult.target.sliced(4);
+
+ // resolve volume to drive letter
+ static const QRegularExpression matchVolumeRe(uR"(^Volume\{([a-z]|[0-9]|-)+\}\\)"_qs,
+ QRegularExpression::CaseInsensitiveOption);
+ auto matchVolume = matchVolumeRe.match(creationResult.target);
+ if (matchVolume.hasMatch()) {
+ Q_ASSERT(matchVolume.capturedStart() == 0);
+ DWORD len;
+ wchar_t buffer[MAX_PATH];
+ const QString volumeName = uR"(\\?\)"_qs + matchVolume.captured();
+ if (GetVolumePathNamesForVolumeName(reinterpret_cast<LPCWSTR>(volumeName.utf16()),
+ buffer, MAX_PATH, &len) != 0) {
+ creationResult.target.replace(0, matchVolume.capturedLength(),
+ QString::fromWCharArray(buffer));
+ }
+ }
+ QCOMPARE(fi.junctionTarget(), QDir::fromNativeSeparators(creationResult.target));
+ QCOMPARE(actualCanonicalFilePath, QFileInfo(creationResult.link).canonicalFilePath());
+ }
}
void tst_QFileInfo::brokenShortcut()