diff options
author | David Faure <david.faure@kdab.com> | 2014-04-23 22:59:34 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-06 01:20:17 +0200 |
commit | 31ce6f50c679e61dc53f09ee1b1637918da38a82 (patch) | |
tree | 12f8fe00be487990f586b2675e40294e486a1245 /tests | |
parent | da24bfe1f7f8a4ece2c1bb9998d6f99f7b4fb137 (diff) |
Add QUrl::fromUserInput overload with a cwd argument.
Useful for any application that can take URLs on the command-line, so that
full paths and relative paths can also be accepted.
Change-Id: I8a2c50f36d60bdc49c065b3065972fd5d45fa12a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 92dbb96817..df090c3de9 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -165,6 +165,8 @@ private slots: void binaryData(); void fromUserInput_data(); void fromUserInput(); + void fromUserInputWithCwd_data(); + void fromUserInputWithCwd(); void fileName_data(); void fileName(); void isEmptyForEncodedUrl(); @@ -2913,6 +2915,52 @@ void tst_QUrl::fromUserInput() QCOMPARE(url, guessUrlFromString); } +void tst_QUrl::fromUserInputWithCwd_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QString>("directory"); + QTest::addColumn<QUrl>("guessedUrlDefault"); + QTest::addColumn<QUrl>("guessedUrlAssumeLocalFile"); + + // Null + QTest::newRow("null") << QString() << QString() << QUrl() << QUrl(); + + // Existing file + QDirIterator it(QDir::currentPath(), QDir::NoDotDot | QDir::AllEntries); + int c = 0; + while (it.hasNext()) { + it.next(); + QUrl url = QUrl::fromLocalFile(it.filePath()); + QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.fileName() << QDir::currentPath() << url << url; + } + QDir parent = QDir::current(); + QVERIFY(parent.cdUp()); + QUrl parentUrl = QUrl::fromLocalFile(parent.path()); + QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl; + + QTest::newRow("nonexisting") << "nonexisting" << QDir::currentPath() << QUrl("http://nonexisting") << QUrl::fromLocalFile(QDir::currentPath() + "/nonexisting"); + QTest::newRow("short-url") << "example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl::fromLocalFile(QDir::currentPath() + "/example.org"); + QTest::newRow("full-url") << "http://example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl("http://example.org"); + QTest::newRow("absolute") << "/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///doesnotexist.txt") << QUrl("file:///doesnotexist.txt"); +#ifdef Q_OS_WIN + QTest::newRow("windows-absolute") << "c:/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///c:/doesnotexist.txt") << QUrl("file:///c:/doesnotexist.txt"); +#endif +} + +void tst_QUrl::fromUserInputWithCwd() +{ + QFETCH(QString, string); + QFETCH(QString, directory); + QFETCH(QUrl, guessedUrlDefault); + QFETCH(QUrl, guessedUrlAssumeLocalFile); + + QUrl url = QUrl::fromUserInput(string, directory); + QCOMPARE(url, guessedUrlDefault); + + url = QUrl::fromUserInput(string, directory, QUrl::AssumeLocalFile); + QCOMPARE(url, guessedUrlAssumeLocalFile); +} + void tst_QUrl::fileName_data() { QTest::addColumn<QString>("urlStr"); |