summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2013-07-14 00:45:14 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-20 21:04:16 +0200
commit0f062f42b9817205aab657dcfaeaa8c3ed302889 (patch)
treee922533f68e046990ed16f991940e99f6e3bc5f1 /tests
parent9d0ff90760bed65451fb665fecf9f770e3b05967 (diff)
QUrl: add fileName() method. Complements QUrl::RemoveFilename.
Change-Id: Ieda43364214c3b7aee43040e176e29ad48c14271 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 5230dbe109..c8945e677c 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -162,6 +162,8 @@ private slots:
void binaryData();
void fromUserInput_data();
void fromUserInput();
+ void fileName_data();
+ void fileName();
void isEmptyForEncodedUrl();
void toEncodedNotUsingUninitializedPath();
void emptyAuthorityRemovesExistingAuthority();
@@ -2826,6 +2828,43 @@ void tst_QUrl::fromUserInput()
QCOMPARE(url, guessUrlFromString);
}
+void tst_QUrl::fileName_data()
+{
+ QTest::addColumn<QString>("urlStr");
+ QTest::addColumn<QString>("expectedDirPath");
+ QTest::addColumn<QString>("expectedPrettyDecodedFileName");
+ QTest::addColumn<QString>("expectedFullyDecodedFileName");
+
+ QTest::newRow("fromDocu") << "http://qt-project.org/support/file.html"
+ << "/support/" << "file.html" << "file.html";
+ QTest::newRow("absoluteFile") << "file:///temp/tmp.txt"
+ << "/temp/" << "tmp.txt" << "tmp.txt";
+ QTest::newRow("absoluteDir") << "file:///temp/"
+ << "/temp/" << QString() << QString();
+ QTest::newRow("absoluteInRoot") << "file:///temp"
+ << "/" << "temp" << "temp";
+ QTest::newRow("relative") << "temp/tmp.txt"
+ << "temp/" << "tmp.txt" << "tmp.txt";
+ QTest::newRow("relativeNoSlash") << "tmp.txt"
+ << 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)";
+}
+
+void tst_QUrl::fileName()
+{
+ QFETCH(QString, urlStr);
+ QFETCH(QString, expectedDirPath);
+ QFETCH(QString, expectedPrettyDecodedFileName);
+ QFETCH(QString, expectedFullyDecodedFileName);
+
+ QUrl url(urlStr);
+ QVERIFY(url.isValid());
+ QCOMPARE(url.adjusted(QUrl::RemoveFilename).path(), expectedDirPath);
+ QCOMPARE(url.fileName(QUrl::PrettyDecoded), expectedPrettyDecodedFileName);
+ QCOMPARE(url.fileName(QUrl::FullyDecoded), expectedFullyDecodedFileName);
+}
+
// This is a regression test for a previously fixed bug where isEmpty didn't
// work for an encoded URL that was yet to be decoded. The test checks that
// isEmpty works for an encoded URL both after and before decoding.