summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 7579c6713d..031a35b380 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -79,6 +79,8 @@ private slots:
void toLocalFile();
void fromLocalFile_data();
void fromLocalFile();
+ void fromLocalFileNormalize_data();
+ void fromLocalFileNormalize();
void macTypes();
void relative();
void compat_legacy();
@@ -1242,16 +1244,6 @@ void tst_QUrl::fromLocalFile_data()
<< QString::fromLatin1("/");
QTest::newRow("data7") << QString::fromLatin1("/Mambo <#5>.mp3") << QString::fromLatin1("file:///Mambo <%235>.mp3")
<< QString::fromLatin1("/Mambo <#5>.mp3");
- QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt")
- << QString::fromLatin1("/a%.txt");
- QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt")
- << QString::fromLatin1("/a%25.txt");
- QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt")
- << QString::fromLatin1("/%80.txt");
- QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt");
- QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt");
- QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt");
- QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt");
}
void tst_QUrl::fromLocalFile()
@@ -1266,6 +1258,41 @@ void tst_QUrl::fromLocalFile()
QCOMPARE(url.path(), thePath);
}
+void tst_QUrl::fromLocalFileNormalize_data()
+{
+ QTest::addColumn<QString>("theFile"); // should support the fromLocalFile/toLocalFile roundtrip (so no //host or windows path)
+ QTest::addColumn<QString>("theUrl");
+ QTest::addColumn<QString>("urlWithNormalizedPath");
+
+ QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("file:///a.txt");
+ QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt")
+ << QString::fromLatin1("file:///a%25.txt");
+ QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt")
+ << QString::fromLatin1("file:///a%2525.txt");
+ QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt")
+ << QString::fromLatin1("file:///%2580.txt");
+ QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:./a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:././a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:b/../a.txt") << QString::fromLatin1("file:a.txt");
+ QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///b/../a.txt") << QString::fromLatin1("file:///a.txt");
+ QTest::newRow("data15") << QString::fromLatin1("/b/.") << QString::fromLatin1("file:///b/.") << QString::fromLatin1("file:///b");
+}
+
+void tst_QUrl::fromLocalFileNormalize()
+{
+ QFETCH(QString, theFile);
+ QFETCH(QString, theUrl);
+ QFETCH(QString, urlWithNormalizedPath);
+
+ QUrl url = QUrl::fromLocalFile(theFile);
+
+ QCOMPARE(url.toString(QUrl::DecodeReserved), theUrl);
+ QCOMPARE(url.toLocalFile(), theFile); // roundtrip
+ QCOMPARE(url.path(), theFile); // works as well as long as we don't test windows paths
+ QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath);
+}
+
void tst_QUrl::macTypes()
{
#ifndef Q_OS_MAC
@@ -2960,6 +2987,9 @@ void tst_QUrl::fromUserInputWithCwd_data()
while (it.hasNext()) {
it.next();
QUrl url = QUrl::fromLocalFile(it.filePath());
+ if (it.fileName() == QLatin1String(".")) {
+ url = QUrl::fromLocalFile(QDir::currentPath()); // fromUserInput cleans the path
+ }
QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.fileName() << QDir::currentPath() << url << url;
}
QDir parent = QDir::current();
@@ -3021,6 +3051,8 @@ void tst_QUrl::fileName_data()
<< QString() << "tmp.txt" << "tmp.txt";
QTest::newRow("encoded") << "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)"
<< "/specials/" << "Print To File (PDF%252FAcrobat)" << "Print To File (PDF%2FAcrobat)";
+ QTest::newRow("endsWithDot") << "file:///temp/."
+ << "/temp/" << "." << ".";
}
void tst_QUrl::fileName()
@@ -3513,7 +3545,7 @@ void tst_QUrl::setComponents_data()
<< PrettyDecoded << "/path" << "trash:/path";
QTest::newRow("path-withdotdot") << QUrl("file:///tmp")
<< int(Path) << "//tmp/..///root/." << Tolerant << true
- << PrettyDecoded << "/root" << "file:///root";
+ << PrettyDecoded << "/tmp/..///root/." << "file:///tmp/..///root/.";
// the other fields can be present and be empty
// that is, their delimiters would be present, but there would be nothing to one side