summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
diff options
context:
space:
mode:
authorWang Fei <wangfeia@uniontech.com>2021-11-16 13:17:39 +0800
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2022-12-23 06:26:44 +0100
commit936cae6b53e8982fb087458745e06721d35341ef (patch)
tree75dfa407218049d42262f9da0430e94918c57ec8 /tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
parent8844c6ef379f466a12a5f4981c78bdb990d92db8 (diff)
Add QFileInfo::readSymLink() to read the raw link path
The existing symLinkTarget() always resolves the symlink target to an absolute path; readSymLink() provides access to the relative path when that is how the symlink references its target. [ChangeLog][QtCore][QFileInfo] Added readSymLink() to read the symlink's raw target, without resolving to an absolute path. Fixes: QTBUG-96761 Change-Id: I360e55f1a3bdb00e2966229ea8de78cf29a29417 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 4b383c0c53..4a2e5cb5e3 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -242,6 +242,7 @@ private slots:
void nonExistingFile();
void stdfilesystem();
+ void readSymLink();
private:
const QString m_currentDir;
@@ -2391,5 +2392,20 @@ void tst_QFileInfo::stdfilesystem()
#endif
}
+void tst_QFileInfo::readSymLink()
+{
+ QString symLinkName("./a.link");
+ const auto tidier = qScopeGuard([symLinkName]() { QFile::remove(symLinkName); });
+
+#ifdef Q_OS_WIN
+ QVERIFY2(CreateSymbolicLink(L"a.link", L"..\\..\\a", SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)
+ != 0,
+ "Failed to create symlink for test");
+#else
+ QVERIFY2(QFile::link("../../a", symLinkName), "Failed to create symlink for test");
+#endif
+ QFileInfo info(symLinkName);
+ QCOMPARE(info.readSymLink(), QString("../../a"));
+}
QTEST_MAIN(tst_QFileInfo)
#include "tst_qfileinfo.moc"