summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2021-06-08 11:59:59 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2021-06-09 04:37:16 +0200
commit915dd3166ad38884dd57c1e439611201d924dc4c (patch)
treefed658e8e21e8997c42e6e5578417f55440006a5 /tests/auto
parente99a9ff495d90e3d97615c8f283cc6d71514035c (diff)
Unify behavior for long path or UNC prefix removal
Split the code out of QDir::fromNativeSeparator into a separate reusable function to remove the above-mentioned prefixes. Fixes and unifies behavior if the prefix was given with slashes instead of backslashes. Add a couple more test cases. Fixes: QTBUG-93868 Change-Id: Ibd94ae283e2fb113f9c2db97475fbc7d89522bbf Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 0564ebdb3641d7325f73dbbf2cbb04e6dca92d83)
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp13
-rw-r--r--tests/auto/corelib/io/qtemporarydir/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp23
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp27
5 files changed, 67 insertions, 6 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index cec01eb752..d43e45e12f 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -1268,9 +1268,20 @@ tst_QDir::cleanPath_data()
QTest::newRow("drive-above-root") << "A:/.." << "A:/..";
QTest::newRow("unc-server-up") << "//server/path/.." << "//server";
QTest::newRow("unc-server-above-root") << "//server/.." << "//server/..";
+
QTest::newRow("longpath") << "\\\\?\\d:\\" << "d:/";
+ QTest::newRow("longpath-slash") << "//?/d:/" << "d:/";
+ QTest::newRow("longpath-mixed-slashes") << "//?/d:\\" << "d:/";
+ QTest::newRow("longpath-mixed-slashes-2") << "\\\\?\\d:/" << "d:/";
+
QTest::newRow("unc-network-share") << "\\\\?\\UNC\\localhost\\c$\\tmp.txt"
<< "//localhost/c$/tmp.txt";
+ QTest::newRow("unc-network-share-slash") << "//?/UNC/localhost/c$/tmp.txt"
+ << "//localhost/c$/tmp.txt";
+ QTest::newRow("unc-network-share-mixed-slashes") << "//?/UNC/localhost\\c$\\tmp.txt"
+ << "//localhost/c$/tmp.txt";
+ QTest::newRow("unc-network-share-mixed-slashes-2") << "\\\\?\\UNC\\localhost/c$/tmp.txt"
+ << "//localhost/c$/tmp.txt";
#else
QTest::newRow("data15") << "//c:/foo" << "/c:/foo";
#endif // non-windows
@@ -1748,6 +1759,8 @@ void tst_QDir::nativeSeparators()
QCOMPARE(QDir::fromNativeSeparators(QLatin1String("\\\\?\\C:\\")), QString("C:/"));
QCOMPARE(QDir::fromNativeSeparators(QLatin1String(R"(\\?\UNC\localhost\c$\tmp.txt)")),
QString("//localhost/c$/tmp.txt"));
+ QCOMPARE(QDir::fromNativeSeparators(QLatin1String(R"(//?/UNC/localhost\c$\tmp.txt)")),
+ QString("//localhost/c$/tmp.txt"));
#else
QCOMPARE(QDir::toNativeSeparators(QLatin1String("/")), QString("/"));
QCOMPARE(QDir::toNativeSeparators(QLatin1String("\\")), QString("\\"));
diff --git a/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt b/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt
index fa8efa114b..fcfd409d5b 100644
--- a/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt
+++ b/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt
@@ -10,3 +10,8 @@ qt_internal_add_test(tst_qtemporarydir
PUBLIC_LIBRARIES
Qt::TestPrivate
)
+
+qt_internal_extend_target(tst_qtemporarydir CONDITION WIN32
+ LIBRARIES
+ shlwapi
+)
diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
index 14f3a10593..94fcc006bb 100644
--- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
+++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
@@ -37,6 +37,7 @@
#include <qset.h>
#include <QtTest/private/qtesthelpers_p.h>
#ifdef Q_OS_WIN
+# include <shlwapi.h>
# include <windows.h>
#endif
#ifdef Q_OS_UNIX // for geteuid()
@@ -159,9 +160,25 @@ void tst_QTemporaryDir::fileTemplate_data()
}
#ifdef Q_OS_WIN
- const auto tmp = QDir::toNativeSeparators(QDir::tempPath()).sliced(QDir::rootPath().size());
- QTest::newRow("UNC") << "\\\\localhost\\C$\\" + tmp + "\\UNC.XXXXXX.tmpDir"
- << "UNC." << ".tmpDir";
+ auto tmp = QDir::toNativeSeparators(QDir::tempPath());
+ if (PathGetDriveNumber((const wchar_t *) tmp.utf16()) < 0)
+ return; // skip if we have no drive letter
+
+ tmp.data()[1] = u'$';
+ const auto tmpPath = tmp + QLatin1String(R"(\UNC.XXXXXX.tmpDir)");
+
+ QTest::newRow("UNC-backslash")
+ << "\\\\localhost\\" + tmpPath << "UNC."
+ << ".tmpDir";
+ QTest::newRow("UNC-prefix")
+ << "\\\\?\\UNC\\localhost\\" + tmpPath << "UNC."
+ << ".tmpDir";
+ QTest::newRow("UNC-slash")
+ << "//localhost/" + QDir::fromNativeSeparators(tmpPath) << "UNC."
+ << ".tmpDir";
+ QTest::newRow("UNC-prefix-slash")
+ << "//?/UNC/localhost/" + QDir::fromNativeSeparators(tmpPath) << "UNC."
+ << ".tmpDir";
#endif
}
diff --git a/tests/auto/corelib/io/qtemporaryfile/CMakeLists.txt b/tests/auto/corelib/io/qtemporaryfile/CMakeLists.txt
index 11d4b991ce..f8419cee87 100644
--- a/tests/auto/corelib/io/qtemporaryfile/CMakeLists.txt
+++ b/tests/auto/corelib/io/qtemporaryfile/CMakeLists.txt
@@ -45,3 +45,8 @@ if(ANDROID AND NOT ANDROID_EMBEDDED)
${android_testdata_resource_files}
)
endif()
+
+qt_internal_extend_target(tst_qtemporaryfile CONDITION WIN32
+ LIBRARIES
+ shlwapi
+)
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index e23df1da2b..7071f2142e 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -40,6 +40,7 @@
#include <QtTest/private/qtesthelpers_p.h>
#if defined(Q_OS_WIN)
+# include <shlwapi.h>
# include <windows.h>
#endif
#if defined(Q_OS_UNIX)
@@ -208,9 +209,29 @@ void tst_QTemporaryFile::fileTemplate_data()
}
#ifdef Q_OS_WIN
- const auto tmp = QDir::toNativeSeparators(QDir::tempPath()).sliced(QDir::rootPath().size());
- QTest::newRow("UNC") << "\\\\localhost\\C$\\" + tmp + "\\QTBUG-74291.XXXXXX.tmpFile"
- << "QTBUG-74291." << ".tmpFile" << "";
+ auto tmp = QDir::toNativeSeparators(QDir::tempPath());
+ if (PathGetDriveNumber((const wchar_t *) tmp.utf16()) < 0)
+ return; // skip if we have no drive letter
+
+ tmp.data()[1] = u'$';
+ const auto tmpPath = tmp + QLatin1String(R"(\QTBUG-74291.XXXXXX.tmpFile)");
+
+ QTest::newRow("UNC-backslash")
+ << "\\\\localhost\\" + tmpPath << "QTBUG-74291."
+ << ".tmpFile"
+ << "";
+ QTest::newRow("UNC-prefix")
+ << "\\\\?\\UNC\\localhost\\" + tmpPath << "QTBUG-74291."
+ << ".tmpFile"
+ << "";
+ QTest::newRow("UNC-slash")
+ << "//localhost/" + QDir::fromNativeSeparators(tmpPath) << "QTBUG-74291."
+ << ".tmpFile"
+ << "";
+ QTest::newRow("UNC-prefix-slash")
+ << "//?/UNC/localhost/" + QDir::fromNativeSeparators(tmpPath) << "QTBUG-74291."
+ << ".tmpFile"
+ << "";
#endif
}