diff options
author | Liang Qi <liang.qi@qt.io> | 2017-03-02 09:04:38 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-03-02 09:04:38 +0100 |
commit | 71264bae08d81bdeceb96133fdb01c370504dfcc (patch) | |
tree | d5dadaac8209d5ef1857a4d65197b9ee12b39848 /tests/auto/corelib/io/qurl/tst_qurl.cpp | |
parent | 5e785c0b83c9908c665f253c131629ac325a21f5 (diff) | |
parent | 6d10f739cd750968d0dd0e9d8fa4b64353a86c6c (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I84097f8e7b3b2128028bd7693c913d6968b82bfe
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 71a0c943d2..e1a999abfb 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -46,6 +46,7 @@ class tst_QUrl : public QObject Q_OBJECT private slots: + void initTestCase(); void effectiveTLDs_data(); void effectiveTLDs(); void getSetCheck(); @@ -182,8 +183,15 @@ private slots: private: void testThreadingHelper(); + + QTemporaryDir m_tempDir; }; +void tst_QUrl::initTestCase() +{ + QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); +} + // Testing get/set functions void tst_QUrl::getSetCheck() { @@ -3045,49 +3053,59 @@ void tst_QUrl::fromUserInputWithCwd_data() // 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()); - if (it.fileName() == QLatin1String(".")) { - url = QUrl::fromLocalFile(QDir::currentPath() + // Use a tempdir with files, for testing specific file names + // We use canonicalPath() on the dir path because ::getcwd() canonicalizes, + // so we get a canonical base path for URLs with "." as working directory. + const QString base = QDir(m_tempDir.path()).canonicalPath(); + QDir::setCurrent(base); // for the tests that use "." as working dir + + // "." + { + const QUrl url = QUrl::fromLocalFile(base #ifdef Q_OS_WINRT + QLatin1Char('/') #endif ); // fromUserInput cleans the path - } - QTest::newRow(("file-" + QByteArray::number(c)).constData()) - << it.fileName() << QDir::currentPath() << url << url; - QTest::newRow(("file-" + QByteArray::number(c) + "-dot").constData()) - << it.fileName() << QStringLiteral(".") << url << url; - ++c; + QTest::newRow("dot-in-path") << "." << base << url << url; + QTest::newRow("dot-in-dot") << "." << QStringLiteral(".") << url << url; + } + + // Existing files + for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt "}) { + const QString filePath = base + '/' + fileName; + QFile file(filePath); + QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath)); + file.write("Hello world\n"); + + const QUrl url = QUrl::fromLocalFile(filePath); + QTest::newRow(fileName) << fileName << base << url << url; + QTest::newRow(QByteArray(fileName) + "-in-dot") << fileName << QStringLiteral(".") << url << url; } + #ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox - QDir parent = QDir::current(); + QDir parent(base); QVERIFY(parent.cdUp()); QUrl parentUrl = QUrl::fromLocalFile(parent.path()); - QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl; + QTest::newRow("dotdot") << ".." << base << parentUrl << parentUrl; #endif - 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"); + QTest::newRow("nonexisting") << "nonexisting" << base << QUrl("http://nonexisting") << QUrl::fromLocalFile(base + "/nonexisting"); + QTest::newRow("short-url") << "example.org" << base << QUrl("http://example.org") << QUrl::fromLocalFile(base + "/example.org"); + QTest::newRow("full-url") << "http://example.org" << base << QUrl("http://example.org") << QUrl("http://example.org"); + QTest::newRow("absolute") << "/doesnotexist.txt" << base << 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"); + QTest::newRow("windows-absolute") << "c:/doesnotexist.txt" << base << QUrl("file:///c:/doesnotexist.txt") << QUrl("file:///c:/doesnotexist.txt"); #endif // IPv4 & IPv6 // same as fromUserInput, but needs retesting - QTest::newRow("ipv4-1") << "127.0.0.1" << QDir::currentPath() << QUrl("http://127.0.0.1") << QUrl::fromLocalFile(QDir::currentPath() + "/127.0.0.1"); - QTest::newRow("ipv6-0") << "::" << QDir::currentPath() << QUrl("http://[::]") << QUrl("http://[::]"); - QTest::newRow("ipv6-1") << "::1" << QDir::currentPath() << QUrl("http://[::1]") << QUrl("http://[::1]"); - QTest::newRow("ipv6-2") << "1::1" << QDir::currentPath() << QUrl("http://[1::1]") << QUrl("http://[1::1]"); - QTest::newRow("ipv6-3") << "1::" << QDir::currentPath() << QUrl("http://[1::]") << QUrl("http://[1::]"); - QTest::newRow("ipv6-4") << "c::" << QDir::currentPath() << QUrl("http://[c::]") << QUrl("http://[c::]"); - QTest::newRow("ipv6-5") << "c:f00:ba4::" << QDir::currentPath() << QUrl("http://[c:f00:ba4::]") << QUrl("http://[c:f00:ba4::]"); + QTest::newRow("ipv4-1") << "127.0.0.1" << base << QUrl("http://127.0.0.1") << QUrl::fromLocalFile(base + "/127.0.0.1"); + QTest::newRow("ipv6-0") << "::" << base << QUrl("http://[::]") << QUrl("http://[::]"); + QTest::newRow("ipv6-1") << "::1" << base << QUrl("http://[::1]") << QUrl("http://[::1]"); + QTest::newRow("ipv6-2") << "1::1" << base << QUrl("http://[1::1]") << QUrl("http://[1::1]"); + QTest::newRow("ipv6-3") << "1::" << base << QUrl("http://[1::]") << QUrl("http://[1::]"); + QTest::newRow("ipv6-4") << "c::" << base << QUrl("http://[c::]") << QUrl("http://[c::]"); + QTest::newRow("ipv6-5") << "c:f00:ba4::" << base << QUrl("http://[c:f00:ba4::]") << QUrl("http://[c:f00:ba4::]"); } void tst_QUrl::fromUserInputWithCwd() |